Skip to main content

Simple loguru_logger_lite built on top of loguru to make a quick setup for basic logging

Project description

loguru_logger_lite

This simple logger is built on top of loguru to make a quick setup for basic logging.

The logger has four transports (called "sinks" here, same as in loguru):

  • stdout
  • stderr
  • file
  • kafka

The standard sinks (stdout, stderr and file) are configured with the same arguments as in loguru (see "add" method in loguru documentation).

Installation

pip install loguru-logger-lite

Usage

get_default_logger() method

The basic logger can be created using get_default_logger method. The get_default_logger method returns preconfigured loguru logger with stdout and stderr sinks. All messages whose level is less than ERROR are sent to stdout while messages whose level is ERROR or above are sent to stderr.

from loguru_logger_lite import Logger

logger = Logger.get_default_logger()

logger.info('Test log message')

The output will be like this:

MODULE: example | COMPONENT: __main__ | PID: 230552 | INFO | 2022-04-08T19:59:36.290220-0400 | Test log message

NOTE: The above log message format will also be a default format if the format option is not provided in sink configuration.

get_logger(sinks) method

The get_logger method is used to create a logger with a custom set of sinks. This method expects a list of Sink objects and returns a loguru logger with the configured sinks.

from loguru_logger_lite import Logger, LogLevels, Sink, Sinks, \
    KafkaSinkOptions, FileSinkOptions

logger = Logger.get_logger([
    Sink(name=Sinks.FILE,
         opts=FileSinkOptions(path='test.log', level=LogLevels.DEBUG)),
    Sink(name=Sinks.KAFKA,
         opts=KafkaSinkOptions(level=LogLevels.TRACE,
                               bootstrap_servers=['localhost:9092'],
                               sink_topic='log_topic'))
])

logger.info('Test log message')

NOTE: When using file and kafka sinks, the output will be a json with text and record root items. The text item is formatted log message and record is loguru Record dictionary (see loguru documentation).

Kafka sink

The kafka sink, along with the basic loguru options, has additional parameters for kafka producer:

  • bootstrap_servers - a list of strings of kafka brokers addresses.
  • producer_config - kafka producer configuration (see kafka-python documentation).
  • sink_topic - a kafka topic name where to send log messages.

get_kafka_sink(options) method

The kafka sink can be used standalone with existing loguru logger:

from loguru import logger
from loguru_logger_lite import Logger, LogLevels, KafkaSinkOptions

kafka_sink = Logger.get_kafka_sink(options=KafkaSinkOptions(
    level=LogLevels.TRACE,
    bootstrap_servers=['localhost:9092'],
    sink_topic='log_topic')
)

logger.add(kafka_sink)

logger.info('Test log message')

LICENSE

MIT

AUTHOR: Dmitry Amanov

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

loguru_logger_lite-0.0.5.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

loguru_logger_lite-0.0.5-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file loguru_logger_lite-0.0.5.tar.gz.

File metadata

  • Download URL: loguru_logger_lite-0.0.5.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for loguru_logger_lite-0.0.5.tar.gz
Algorithm Hash digest
SHA256 92da602247206ef6e6de031b3af548d80889ee66d49118bec6d069b7e04bcc2b
MD5 cd385204a7553261d5e40155dc2553fd
BLAKE2b-256 0a3525318d2c2a07acf7b84d58274c7cbccf48f5b2f9556aed2145bfcc058079

See more details on using hashes here.

File details

Details for the file loguru_logger_lite-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for loguru_logger_lite-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7f5940fdc086cf602251b4f9336611fd80ea78842034a275331dd7de56fd1d1e
MD5 3669930f3930a91156d760cfbaf4c3a4
BLAKE2b-256 df4ebcd7a4e499768ff1256ef3ad969071545084d954160322633028e7f11a0a

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