Skip to main content

No project description provided

Project description

minlog

a minimal, flexible 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.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: minlog-0.5.1.tar.gz
  • Upload date:
  • Size: 4.3 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.1.tar.gz
Algorithm Hash digest
SHA256 cc81ce0a6fca4a428448f6dfb96b059f53a64068e2bd575fff5495947822c94c
MD5 4ebefa68f7638286d0645bf0d49309ec
BLAKE2b-256 7687c254eafb688e11f2952b6077b69bf27b3cf6472039556e61d1e7ea24e1cb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: minlog-0.5.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c696bc6004d5da77dc51a00ba00bf9a7ce3d076652ecd6183bac7316dfda268
MD5 070aea94f261ab7dd0f6bfbd1dc3067a
BLAKE2b-256 d839e8ebb8e75edf2900837d670e3cfd2dbe1a0d89b7feb3d19bab0f7792dad1

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