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.fileConfigto 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
SERVICEenvironment variable but you might as well provide a fixed value.
Project details
Release history Release notifications | RSS feed
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.3.tar.gz
(2.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
gelf-0.0.3-py3-none-any.whl
(3.5 kB
view details)
File details
Details for the file gelf-0.0.3.tar.gz.
File metadata
- Download URL: gelf-0.0.3.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7732ea0a3380f6c9440daccd2aec4dfd56901de6d956ad6fca2a449a73039d6
|
|
| MD5 |
c26acbe4adc1fed1833ae51e4ae68a6e
|
|
| BLAKE2b-256 |
1c3454d3a0fa71b6be8f9c3c3847ba7ef51daae48c33ae74fd65a6e7c7506498
|
File details
Details for the file gelf-0.0.3-py3-none-any.whl.
File metadata
- Download URL: gelf-0.0.3-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a60845bc3df7c47af1f78c3df865aebc6bd630ffec121199fbb9754c0687717
|
|
| MD5 |
16cf8ac1fcfddb22c772f3c82870146f
|
|
| BLAKE2b-256 |
ab48bc59429e76a7c31d051fadaa7b41e4c9a87367df5ea455a722fb9d4cfd3a
|