Logifire v0.0.2
Simplifying the use of logs based on build-in logging.
Main features
- The ability to configure a pause in sending messages, even if the service is running on different servers.
- Modern log message formatting with Python
format
way - Support for any handlers based on the logging.Handler
- Slack handler
Install
pip install logifire
Minimal example
from logifire import Logifire
log = Logifire()
log.debug("Test arg='{}' and kwargs: foo='{foo}', bar='{bar}'", "first arg", foo="fval", bar="bval")
Post-configuration example
import logging
from logifire import Logifire, Logbranch
log = Logifire(branches=[
logging.FileHandler('main.log')
])
import logging
from logifire import Logbranch
from logifire.handlers import SysLogifireHandler
from shared.config import log
log.set_name('some_service')
log.set_level(logging.INFO)
log.add(
Logbranch(SysLogifireHandler(), level=logging.WARNING)
)
Example with log mute feature
This example sets up a Logifire (DEBUG as main level) with a Syslog handler and a Slack handler with a 5-second mute using Memcached.
This allows all DEBUG-level messages to be written to syslog and CRITICAL level messages to be sent to the Slack channel, but no more than once every 5 seconds.
Since Memcached (in this case) is used as the backend for mute, it'll work across the entire cluster if the service is running on multiple servers.
import logging
from logifire import Logifire, Logbranch
from logifire.blowout import BlowoutMemcached
from logifire.handlers import SysLogifireHandler, SlackLogifireHandler
log = Logifire(
name='my_service',
level=logging.DEBUG,
branches=[
Logbranch(SysLogifireHandler()),
Logbranch(
handler=SlackLogifireHandler("<token>"),
level=logging.CRITICAL,
blowout_seconds=5
)
],
blowout=BlowoutMemcached([('127.0.0.1', 11211)])
)
log.debug("Test debug message")
log.info("Test info message")
log.critical("Test critical message")
Copyright (C) 2022 by Dmitry Parfyonov parfyonov.dima@gmail.com
MIT License, see http://opensource.org/licenses/MIT