Skip to main content

Logs manager with mute log feature at different levels: process, server, cluster

Project description

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()  # init log with stderr handler by default

log.debug("Test arg='{}' and kwargs: foo='{foo}', bar='{bar}'", "first arg", foo="fval", bar="bval")
# 2022-05-27T23:27:42.721 28696   [DEBUG   ] main.<module>: Test arg='first arg' and kwargs: foo='fval', bar='bval'

Post-configuration example

# shared/config.py

import logging
from logifire import Logifire, Logbranch

log = Logifire(branches=[
    logging.FileHandler('main.log')
])
# some_service/config.py

import logging
from logifire import Logbranch
from logifire.handlers import SysLogifireHandler

from shared.config import log

log.set_name('some_service')  # set name for logger
log.set_level(logging.INFO)   # set global level
log.add(                      # add syslog for only warnings
    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',  # your service name
    level=logging.DEBUG,  # main log level
    branches=[
        Logbranch(SysLogifireHandler()),  # add Syslog handler, you can use any logging.Handler
        Logbranch(  # add Slack handler
            handler=SlackLogifireHandler("<token>"),
            level=logging.CRITICAL,  # send only critical messages to Slack
            blowout_seconds=5  # after sending a message, mute the sending for 5 seconds
        )
    ],
    blowout=BlowoutMemcached([('127.0.0.1', 11211)])  # use Memcached for the mute feature (pymemcache lib required)
)

log.debug("Test debug message")  # send to syslog
log.info("Test info message")  # send to syslog
log.critical("Test critical message")  # send to syslog and slack

Copyright (C) 2022 by Dmitry Parfyonov parfyonov.dima@gmail.com
MIT License, see http://opensource.org/licenses/MIT

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

logifire-0.0.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

logifire-0.0.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logifire-0.0.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.9

File hashes

Hashes for logifire-0.0.2.tar.gz
Algorithm Hash digest
SHA256 94c3aa9b87acaae3b209a294055494d5ba0a7a64c28d28aad0e5e85c9dd70e17
MD5 e786b00bfedd1114c387e925fe29cf11
BLAKE2b-256 c9cc8de32c370a5fda50de9f6b570f523708cf316a1ba0656ee0d8ad6682dad0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logifire-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.9

File hashes

Hashes for logifire-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e88af2a7d2a0aa5bbbe6f49bd72605ec6fc44d135010cba8c2fdd7cab207ac13
MD5 9ca4d7059af63e9ba9e2c5a4534932be
BLAKE2b-256 f9ac6c1d5b3b2439d3c75120d8a9a25f7a769323701d96b43a337fe30a35ab45

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