# Logging from your Python code

You can extend and customize AxoSyslog easily by writing [destinations](../../docs/axosyslog-core/chapter-destinations/python-destination/index.md), [parsers](../../docs/axosyslog-core/chapter-parsers/python-parser/index.md), [template functions](../../docs/axosyslog-core/chapter-destinations/python-destination/index.md#template-function-python), and [sources](../../docs/axosyslog-core/chapter-sources/python-source/index.md) in Python.

To debug and troubleshoot your Python code, AxoSyslog allows you to use the `logger()` method to send log messages to the [`internal()`](../../docs/axosyslog-core/chapter-sources/configuring-sources-internal/index.md) source of AxoSyslog. That way the diagnostic messages of your Python code are treated the same way as other such log messages of AxoSyslog. This has the following benefits:

  * The `logger()` method respects the log level settings of AxoSyslog. You can write error, warning, info, debug, and trace level messages.

  * You can follow what your Python code is doing even if AxoSyslog is running as a daemon in the background.




Logging to the `internal()` source is available in AxoSyslog version 3.20 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 AxoSyslog 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); };
         
```




Last modified July 2, 2023: [Change highlight mode of code examples (2f8a959)](<https://github.com/axoflow/axosyslog-core-docs/commit/2f8a95937c6498193e7168ce8b0dc831e9f0f8ad>)