Pushing logs with a SDK - Python 3.x - logging-ldp
Objective
This guide will show you how to push your logs to Logs Data Platform using Python 3.x.
logging-ldp is intended to be a high performance logging formatter and handler to send log entries into Logs Data Platform.
This package includes:
- a TCP/TLS handler to send log entries over TCP with TLS support.
- a formatter to convert logging record into GELF(1.1).
- a facility to ensure fields suits the LDP naming conventions.
Requirements
To complete this guide you will need:
- Python 3, 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 logging-ldp, make sure you have the latest version:
Using sources
logging-ldp is available on the OVH github repository and can be installed manually:
How to send logs
The following example shows how to send log in Graylog TCP input:
Send additional static meta data
To automatically append meta data on all your logs, you can implement an alternate Schema:
The log entry sent to Graylog will be something like:
Note: The result is "pretty printed" only for the documentation.
Send additional intermittent meta data
To define occasional meta data, you can define a Schema with Nested sub-items:
The log entry sent will be:
As we can see:
- Objects are transformed to flatten dictionaries:
manager.nameis renamedmanager_name. - Fields are types using the LDP naming convention:
manager.ageis renamedmanager_age_int - Null values are not sent:
user.age. - You can set
required=Trueto force meta data value ordefault=xxxto add data automatically.
Go further
- Getting Started: Quick Start
- Documentation: Guides
- Community hub: https://community.ovh.com
- Create an account: Try it!