1

I'm working on a python script and I'm using the python logging module for writing some information into a log file (see http://docs.python.org/howto/logging.html).

Here is a small example (also from the mentioned page):

import logging
import logging.config

logging.config.fileConfig('logging.conf')

# create logger
logger = logging.getLogger('simpleExample')

# 'application' code
logger.info('info message')
logger.error('error message')

Now I want to create a c-extension for python, which I want to import in my program.

The question is: How can I write information in my log-file from my c-code? Is there a way of using the logging-module from a python c-extension?

Thank you for any comments!

firehead
  • 71
  • 7
  • See also [this gist example](https://gist.github.com/hensing/0db3f8e3a99590006368). –  Oct 20 '16 at 02:33

1 Answers1

2

The "very high-level C API" has a number of tools for executing pure python code from C. Start by looking at http://docs.python.org/c-api/veryhigh.html#PyRun_String .

Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485