Documentation OVH

Push logs with Python using Djehouty

Last updated 5th March, 2018


This guide will show you how to push your logs to Logs Data Platform using Python.

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.


To complete this guide you will need:



Using pip

You can use pip to install Djehouty, make sure you have the latest version:

$ sh-4.2# pip install --upgrade pip
Successfully installed pip-<version> 
$ sh-4.2# pip install --upgrade djehouty
Successfully installed djehouty-<version> setuptools-18.3.1

Using sources

Djehouty is available on the OVH github repository and can be installed manually:

$ sh-4.2$ git clone
Cloning into 'djehouty'...
remote: Counting objects: 58, done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 58 (delta 26), reused 0 (delta 0)
Receiving objects: 100% (58/58), 9.62 KiB | 0 bytes/s, done.
Resolving deltas: 100% (26/26), done.
Checking connectivity... done.

$ sh-4.2$ cd djehouty
$ sh-4.2$ python install
Using /usr/lib/python2.7/site-packages
Finished processing dependencies for djehouty==<version>

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 endpoint <your_cluster> (Same url than your Graylog dashboard)
port Refer to the PaaS Logs ports list below
level logging.DEBUG or highter
use_tls True or False (depends on the chosen port)
static_fields * {"X-OVH-TOKEN": "xxxx"}
null_character True (LTSV: Not Supported)
Syslog RFC5424 Gelf LTSV line LTSV nul Cap’n’Proto
TCP/TLS 6514 12202 12201 12200 12204
TCP 514 2202 2201 2200 2204
UDP 514 2202 Not Supported Not Supported Not Supported

The complete list of parameters supported by Djehouty can be found on github.

Example: Use case with GELF over TCP/TLS

import logging
from djehouty.libgelf.handlers import GELFTCPSocketHandler

gelf_logger = logging.getLogger('djehouty-gelf')
    host            = "<your_cluster>",
    port            = 12202,
    static_fields   = {"X-OVH-TOKEN": "XXXXX-XXXXXX"},
    use_tls         = True,
    level           = logging.DEBUG,
    null_character  = True,

Example: use case with LTSV over TCP/TLS

import logging
from djehouty.libltsv.handlers import LTSVTCPSocketHandler

ltsv_logger = logging.getLogger('djehouty-ltsv')
    host            = "<your_cluster>",
    port            = 12201,
    static_fields   = {"X-OVH-TOKEN": "XXXXX-XXXXXX"},
    use_tls         = True,
    level           = logging.DEBUG

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:

mylogger = logging.LoggerAdapter(
    extra = {"myvar": 5}

You can add specific log meta for each entry using the extra parameter, the following example uses the LTSV logger defined above:"Hello '%s'", 'Cedric', extra={"lang": 'en'})"Bonjour '%s'", 'Cedric', extra={"lang": 'fr'})

Go further

Cet article vous a-t-il été utile ?

Génial ! Ravi d'avoir pu vous aider.

Pourquoi n'êtes-vous pas satisfait ?

Merci votre avis a été pris en compte.

Ces guides pourraient également vous intéresser...