Skip to main content

Library that provides classes for GELF logging!

Project description

Python GELF

Install from PyPI

pip install gelf

Configure handler from a python script

import logging
import time
from uuid import uuid4

from gelf.handler import GELFHandlerTCP

logger = logging.getLogger("example.module")
logger.setLevel(logging.DEBUG)

handler = GELFHandlerTCP(
    host="127.0.0.1",
    port=12201,
    service="example",
    include_extra_fields=True,
    debug=True,
)
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
# not strictly needed, this is to display logs on stdout
logger.addHandler(logging.StreamHandler())

logger.info(
    "This message gives a lot of information",
    extra={
        "request_id": "4edba63411eb4c8f808e32e904d29c1c",
        "user_id": "bf5089c16355401a9bff3efd6b2ada2e"
    },
)

Configure handler using a config file

  • In python script use logging.config.fileConfig to load logging config from file
import logging
import logging.config
import time
from uuid import uuid4

logging.config.fileConfig("logging.conf")

logger = logging.getLogger("example.module")

logger.info(
    "This message gives a lot of information",
    extra={
        "request_id": "4edba63411eb4c8f808e32e904d29c1c",
        "user_id": "bf5089c16355401a9bff3efd6b2ada2e"
    },
)
  • Put your logging config in a file. Here logging.conf
[formatters]
keys = 

[handlers]
keys = stdout,gelf

# not strictly needed, this is to display logs on stdout
[handler_stdout]
class = logging.StreamHandler
level = DEBUG

[handler_gelf]
class = gelf.handler.GELFHandlerTCP
args = ('localhost', '12201', os.getenv('SERVICE', 'unknown'))

[loggers]
keys = root

[logger_root]
handlers = stdout,gelf
level = DEBUG

NOTE: In this example service field of log records is retrieved from SERVICE environment variable but you might as well provide a fixed value.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gelf-0.0.2.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gelf-0.0.2-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file gelf-0.0.2.tar.gz.

File metadata

  • Download URL: gelf-0.0.2.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for gelf-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b5ea3724ba2f4d64b9fb68124d69598fec7a0b99007db6e4d6e60e65aa308a5d
MD5 777817b9059c49bbec8992c176b8a326
BLAKE2b-256 87bbb38f5788356ddc4d3aa813d2581e6a3cc6f73bb06f22750a9d93656e7a16

See more details on using hashes here.

File details

Details for the file gelf-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: gelf-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for gelf-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 caeba2f051b2fe2dac2f9d4eb3c6661037ab22f8a0f2fa69c7104661dbd74042
MD5 fb280c09ba7e2e2f2c7335944301e17c
BLAKE2b-256 7d9c6cbdaf52414d1b87152203a01a92dfea6c5d1b3ba4a29012ac583efbf1c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page