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
Release history Release notifications | RSS feed
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.6.0.tar.gz
(4.2 kB
view details)
Built Distribution
File details
Details for the file minlog-0.6.0.tar.gz
.
File metadata
- Download URL: minlog-0.6.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c8a956abb2d5e788d19b5d8810c40d991041bf2d241d0f5b7064199ced9bd2f |
|
MD5 | 1f92ed7fd34b091b8c0673bc0a8181c1 |
|
BLAKE2b-256 | 03229290ba26e08ad7f4505ffc87aaf9cbb033c196075f51532349b6107e0fbf |
File details
Details for the file minlog-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: minlog-0.6.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40377c2291c8efab16de1f53960ecabbd909c0f4b52911f4912a95e30a7e1abb |
|
MD5 | 1605560a220d785f11b33f1e8e64218b |
|
BLAKE2b-256 | f09d814bea46ab8efbcd9044c85c0dc3bae975f5705ecff3b14d951ed0804913 |