Tchater maintenant avec le support
Tchattez avec un ingénieur du support

syslog-ng Premium Edition 7.0.18 - Release Notes

Logging from your Python code

You can extend and customize syslog-ng PE easily by writing destinations, parsers, template functions, and sources in Python.

To debug and troubleshoot your Python code, syslog-ng PE allows you to use the logger() method to send log messages to the internal() source of syslog-ng PE. That way the diagnostic messages of your Python code are treated the same way as other such log messages of syslog-ng PE. This has the following benefits:

  • The logger() method respects the log level settings of syslog-ng PE. You can write error, warning, info, debug, and trace level messages.

  • You can follow what your Python code is doing even if syslog-ng PE is running as a daemon in the background.

Logging to the internal() source is available in syslog-ng PE version 7.0.14 and later.

To send log messages to the internal() source from Python

  1. Add the following import to your Python code:

    import syslogng
  2. Create a logger object:

    logger = syslogng.Logger()
  3. Use the logger object in your Python code, for example:

    logger.info("This is a sample log message send from the Python code.")

    You can use the following log levels: logger.error, logger.warning, logger.info, logger.debug, logger.trace

  4. Make sure that your syslog-ng PE configuration includes the internal() source, for example:

    source s_internal { internal(); };
    destination d_internal { file("/var/log/internal.txt"); };
    log {source(s_internal); destination(d_internal); };
    
Documents connexes