Loguru extension for log in GELF payload format.
Project description
gelfguru
A Loguru extension for handling log messages and adapt to GELF payload pattern, without modifying built-in Loguru methods call. This library was created especially for applications running in Docker environment with GELF Logging Driver.
Features:
- Dont modify call methods Loguru, like
logger.trace,logger.info,logger.infoetc; - Create new methods for
loggerinstance, with all RFC-5424 Severity level; - Associates RFC-5424 Severity Levels Numerical Codes in GELF field.
- Filter logs by environment variable
GELFGURU_LEVEL.
Installation
pip3.7 install gelfguru
How to Use
If you configure Loguru instance with gelfguru, you only need to execute:
from loguru import logger
from gelfguru import configure_gelf_output
configure_gelf_output()
logger.trace('loguru trace calls equals gelfguru debug calls')
logger.info('Numeric level RFC-5424')
logger.emergency('Implemented RFC-5424 Syslog Severity Logs')
Log Levels
GELF log level is equal to the standard syslog levels.
| gelfluru | Syslog Severity | Numerical Code | Description |
|---|---|---|---|
emergency |
Emergency | 0 | System is unusable. A panic condition |
alert |
Alert | 1 | Action must be taken immediately. A condition that should be corrected immediately, such as a corrupted system database.[ |
critical |
Critical | 2 | Critical conditions. Hard device errors |
error |
Error | 3 | Error conditions. |
warning |
Warning | 4 | Warning conditions |
success, notice |
Notice | 5 | Normal but significant condition. Conditions that are not error conditions, but that may require special handling |
info |
Informational | 6 | Informational messages |
debug, trace |
Debug | 7 | Debug-level messages. Messages that contain information normally of use only when debugging a program. |
Example:
from loguru import logger
from gelfguru import configure_gelf_output
configure_gelf_output()
logger.trace('loguru trace calls equals gelfguru debug calls')
# {
# "version": "1.1",
# "short_message": "trace\n",
# "full_message": "trace\n",
# "timestamp": 1593137655.309429,
# "level": 7,
# "line": 1,
# "_file": "<ipython-input-4-698cb139534b>",
# "_context": {
# "module": "__main__:<module>:1",
# "process": "MainProcess",
# "thread": "MainThread"
# }
# }
logger.info('Change numeric level value, in the case, is used RFC-5424 numeric level value')
# {
# "version": "1.1",
# "short_message": "Change numeric level value, in the case, is used RFC-5424",
# "full_message": "Change numeric level value, in the case, is used RFC-5424 numeric level value",
# "timestamp": 1593137655.42884,
# "level": 6,
# "line": 1,
# "_file": "<ipython-input-5-d527b5b194dc>",
# "_context": {
# "module": "__main__:<module>:1",
# "process": "MainProcess",
# "thread": "MainThread"
# }
# }
logger.emergency('Implemented RFC-5424 Syslog Severity Logs')
# {
# "version": "1.1",
# "short_message": "Implemented RFC-5424 Syslog Severity Logs",
# "full_message": "Implemented RFC-5424 Syslog Severity Logs",
# "timestamp": 1593137657.236526,
# "level": 0,
# "line": 1,
# "_file": "<ipython-input-6-5c45ca4c1de6>",
# "_context": {
# "module": "__main__:<module>:1",
# "process": "MainProcess",
# "thread": "MainThread"
# }
# }
logger.bind(new_field="i am additional filed gelf").error('iste natus error sit')
# {
# "version": "1.1",
# "short_message": "iste natus error sit",
# "full_message": "iste natus error sit",
# "timestamp": 1593138435.430722,
# "level": 3,
# "line": 18,
# "_file": "/home/augustoliks/github/loguru-gelf-extension/tests/test_loguru_gelf_extension.py",
# "_context": {
# "module": "test_loguru_gelf_extension:test_loguru_calls:18",
# "process": "MainProcess",
# "thread": "MainThread"
# },
# "_new_field": "i am additional filed gelf"
# }
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
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
File details
Details for the file gelfguru-0.1.3.tar.gz.
File metadata
- Download URL: gelfguru-0.1.3.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.7.7 Linux/5.6.15-200.fc31.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7173beaf862ce0d5bfc94cdf5906fe616b10ed4c7a7d2ab08802fb5015e9b38d
|
|
| MD5 |
0a4a8bf847a177954f58614802ffa07e
|
|
| BLAKE2b-256 |
0215ec49aa818560759e05866630f749601fa379564150054cc5f32528bc64a4
|
File details
Details for the file gelfguru-0.1.3-py3-none-any.whl.
File metadata
- Download URL: gelfguru-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.7.7 Linux/5.6.15-200.fc31.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9636dbfbac083eede6011164a0ff4ddde8cc20555742f36d7ef951f25d81568
|
|
| MD5 |
e6388a3d4a91f7ba04698320b9799ffa
|
|
| BLAKE2b-256 |
282936d571eec2ccaac1a5e3c49b07754815e04d4ecb0276e8fc281405911901
|