Logz.io Python Handler setup

Logz.io Python Handler sends logs in bulk over HTTPS to Logz.io. Logs are grouped into bulks based on their size.

If the main thread quits, the handler tries to consume the remaining logs and then exits. If the handler can’t send the remaining logs, they are written to the local file system for later retrieval.

Add the dependency to your project

Navigate to your project’s folder in the command line, and run this command to install the dependency.

pip install logzio-python-handler

Configure Logz.io Python Handler for a standard Python project

Use the samples in the code block below as a starting point, and replace the sample with a configuration that matches your needs.

For a complete list of options, see the configuration parameters below the code block.👇



# Parameters must be set in order. Replace these parameters with your configuration.




format={"additional_field": "value"}


Arguments must be configured in the order shown. For example, to set debug-flag to True, you need to set every argument that comes before it.

Your Logz.io account token.
Replace <ACCOUNT-TOKEN> with the token of the account you want to ship to.
log-type python
The log type, shipped as type field. Used by Logz.io for consistent parsing. Can’t contain spaces.
timeout 3
Time to wait between log draining attempts, in seconds.
listener-url https://listener.logz.io:8071
Listener URL and port.
Replace <LISTENER-URL> with your region’s listener URL. For more information on finding your account’s region, see Account region.
debug-flag False
Debug flag. To print debug messages to stdout, True. Otherwise, False.

Code sample

import logging
import logging.config

# If configuration is stored at ./myconf.conf:

logger = logging.getLogger('superAwesomeLogzioLogger')

logger.info('Test log')

    logger.exception("Supporting exceptions too!")

To add dynamic metadata to your logger other than the constant metadata from the formatter, you can use the extra parameter. Key-value pairs passed in extra are shown as new fields in Logz.io. Please note that you can’t override default fields from the python logger, such as lineno or thread.

logger.info('Warning', extra={'extra_key':'extra_value'})