Skip to main content

a neat and simple minimalistic logging library for python

Project description

minlog

a neat and simple minimalistic logging library for python.

installation

pip install minlog

usage

from minlog import Logger

# create a logger instance
my_logger = Logger()

# or use the global logger instance
from minlog import logger
my_logger = logger.logger_for("stuff")

# log messages with different severity levels
logger.debug("debugging info")
logger.trace("trace message")
logger.info("general information")
logger.warn("warning message")
logger.error("error condition")
logger.crit("critical failure")

controlling verbosity

# show only errors and critical messages
logger.be_quiet()

# show all messages including debug and trace
logger.be_verbose()

# show messages at debug level
logger.be_debug()

# temporarily change verbosity using context manager
with logger.verbosity(Verbosity.DEBUG):
    logger.debug("this will be shown")
    logger.trace("this too")

# conditional logging based on verbosity
if logger.is_verbosity_above(Verbosity.ERROR):
    logger.error("this will only show in verbose modes")

source logging

organize logs by source/context:

# create loggers for different components
app_logger = logger.logger_for("app")
db_logger = logger.logger_for("db")

app_logger.info("message from application")
db_logger.warn("database warning")

# temporary subsource context
with logger.subsource("api"):
    logger.info("message with api context")

class decoration

automatically add logging to classes:

from minlog import logged

@logged  # uses class name as source
class MyClass:
    def do_something(self):
        self.logger.info("doing something")

@logged("custom_source")  # specify custom source
class MyOtherClass:
    def do_something(self):
        self.logger.info("doing something else")

advanced features

# force a message regardless of verbosity
logger.force_log("important message")

# conditional logging based on verbosity threshold
logger.log_only_when_quieter_than("debug info", Verbosity.DEBUG)

# multi-line messages are supported
logger.info("line one\nline two")

# rich text formatting characters are handled correctly
logger.info("message with [brackets]")
logger.info("message with [red]color[/red]")

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

minlog-0.5.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

minlog-0.5.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file minlog-0.5.2.tar.gz.

File metadata

  • Download URL: minlog-0.5.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for minlog-0.5.2.tar.gz
Algorithm Hash digest
SHA256 57e205a64b578aeb7692d81a64ee943e19de8e6954310439123d6e86ada22ee2
MD5 9059123740c146c0805cfdb61c4e0e26
BLAKE2b-256 56ba918dd6031b67f0d5ec1a13a826dce659ecb0ce0bab04db37fbf14e9c9e9b

See more details on using hashes here.

File details

Details for the file minlog-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: minlog-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for minlog-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 89d017f98b452b3ba2df8cbfc5d4d4a19ade65fd54f22351a20ad1e66adefae9
MD5 1ecb61db335f289c289ea75df567e0d2
BLAKE2b-256 0897b45798827641719d947e65972ce785ab1d33d9a3dbcf41367809b849f796

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page