Python logging library with support for multiple destinations
Project description
loghandler
loghandler allows you to easily log messages to multiple endpoints.
Using
Install loghandler via pip
pip install loghandler
In your code import LogHandler and initalize it.
from loghandler import LogHandler
logger = LogHandler({
"log_level": "DEBUG",
"outputs": [
{
"type": "STDOUT"
}
]
})
You can now log messages to all your outputs via:
logger.log('fatal', Exception("Something went HORRIBLY wrong"))
Supported endpoints
- STDOUT
- elasticsearch
Coming soon
- database (MySQL, PostgreSQL, SQLite, ...)
- logstash
- sentry
And probably more.
Endpoints
General Configuration
All endpoints accept a few global settings. They are shown below.
log_level
: For the output it's applied to, this will overrule the global configuration level
STDOUT
To use STDOUT as a log endpoint, add the following to your outputs array.
{
"type": "STDOUT"
}
Elasticsearch
To use elasticsearch as a log endpoint, add the following to your outputs array.
{
"type": "elasticsearch",
"config": {
"hosts": ["https://your-es-host.com:9243"],
"ssl": True,
"verify_certs": True,
"index": "your-index", # Index will be created if it doesn't exist
"api_key": ("your-api-key-id", "your-api-key-secret")
}
}
Next time something is logged you should see something like the following under your index:
{
"_index" : "logs",
"_type" : "_doc",
"_id" : "some-id",
"_score" : 1.0,
"_source" : {
"timestamp" : "2021-11-05T04:16:25.250206",
"level" : "DEBUG",
"hostname" : "YOUR-HOSTNAME",
"message" : "division by zero",
"occurred_at" : {
"path" : "/somepath/test.py",
"line" : 22
}
}
}
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
Built Distribution
Hashes for loghandler-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0e721612191cbc1fbb029b929abf61472eadc78650c3674e3fe30cfc19db802 |
|
MD5 | 367cabfa85ec74c128c2cda0985856c7 |
|
BLAKE2b-256 | ba4af88dbc51131274674e3f00cbbc6fc5bba6dc2e58c17d0b4835f08038aaf3 |