Logger shared by all modules in a program. Simplification of standard Python logging
Project description
Singleton Logging Service
Logging service that is guaranteed to be a singleton. Based on Python logging, but every instantiation of LoggingService from any of an application's modules returns the same logger instance.
###Examples:
from logging_service import LoggingService
self.log = LoggingService()
self.log.info("Constructing output file names...")
self.log.err("Failed to construct output file names...")
self.log.warn("Output file names are unusual...")
self.log.debug("Constructing output file names foo.bar, fum.txt...")
This API is more primitive than the hierarchical native logging module, but hopefully simple to use. One can:
- Log to a file,
- The console, or
- Both
A single formatter is built in for info/debug/warn/err. Example:
my_module.py(290375): 2020-09-03 14:58:33,017;INFO: Start Epoch [1/50]
When first creating a LoggingService instance, the following options are available in the constructor; all are optional:
logging_level=logging.INFO # the Python logging package's constants
logfile=None, # destination file; None implies console only
tee_to_console=True, # if logfile is specified, also log to console
msg_identifier=None, # shown at start of each msg; default is module name
rotating_logs=True, # if logging to file, rotate log if size exceeded
log_size=1000000, # max log size for rotation
max_num_logs=500, # max number of full logs to retain
logger_name=None # name for the logger instance
After creation a logger instance may only be modified like this:
- my_logger.logging_level = logging.NEW_LEVEL
- my_logger.log_file = '/tmp/new_logfile'
where logging levels are the usual logging.INFO,
logging.WARN
, etc.
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
Built Distribution
File details
Details for the file logging-singleton-1.0.1.tar.gz
.
File metadata
- Download URL: logging-singleton-1.0.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc123477574fe76abd776734ff681c3abe1eddd1cb24df5c327611b54d5c44a8 |
|
MD5 | 426f1199c264219ab2f965d963a86134 |
|
BLAKE2b-256 | d92aedcfff054db19664c60adc1ca77a2a2dddfecb7f84d1049da7417813a361 |
File details
Details for the file logging_singleton-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: logging_singleton-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db84415402b719c1398ac812851e8e26b3ffdbd71d7261161bed1b38d36af9c0 |
|
MD5 | 23fe7b951869422de80c14540779fe82 |
|
BLAKE2b-256 | 3dded3bdf139920ddbe04db96b3d478ead176bda9734d85fc62b3d368b6eeeed |