Pushing logs with a logging library - Python 2.x - Djehouty
Objective
This guide will show you how to push your logs to Logs Data Platform using Python 2.x.
Djehouty is intended to be a set of logging formatters and handlers to easily send log entries into Logs Data Platform.
This package includes:
- for GELF:
- a TCP/TLS handler to send log entries over TCP with TLS support.
- a formatter to convert logging record into GELF(1.1).
- for LTSV:
- a TCP/TLS handler to send log entries over TCP with TLS support.
- a formatter to convert logging record into LTSV.
Requirements
To complete this guide you will need:
- Python 2, we recommend to install pip.
- Activated your Logs Data Platform account.
- To create at least one Stream and get its token.
Instructions
Install
Using pip
You can use pip to install Djehouty, make sure you have the latest version:
Using sources
Djehouty is available on the OVH github repository and can be installed manually:
How to send logs
The following examples assume that you already have a working stream. Moreover, you will have to change the address and the ports of the endpoint for the one you have been assigned to. To retrieve the address and the ports of your endpoint, head to the About page in the Manager. To send log messages, just use the handler of the desired format with the following parameters ('*' means required):
| Parameter | Gelf | LTSV |
|---|---|---|
| host * | your assigned endpoint. Ex : gra1.logs.ovh.com | |
| port * | Refer to the PaaS Logs ports list | |
| level | logging.DEBUG or higher | |
| use_tls | True or False (depends on the chosen port) | |
| static_fields * | {"X-OVH-TOKEN": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"} | |
| null_character | True | Not Supported |
The complete list of parameters supported by Djehouty can be found on github.
Example: Use case with GELF over TCP/TLS
Example: Use case with LTSV over TCP/TLS
Send additional meta data
If you have many handler, you can use the logging.LoggerAdapter class to add extra.
The following example uses the LTSV logger defined above:
You can add specific log meta for each entry using the extra parameter, the following example uses the LTSV logger defined above:
Go further
- Getting Started: Quick Start
- Documentation: Guides
- Community hub: https://community.ovh.com
- Create an account: Try it!