Skip to main content

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

For convenience, the logging levels logging.DEBUG, logging.INFO, etc. are available in this package as enums: LoggingLevel.DEBUG, LoggingLevel.INFO, etc. Just import LoggingLevel with LoggingService.

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=LoggingLevel.INFO    # equivalent to 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 = LoginLevel.<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

logging_singleton-1.0.4.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

logging_singleton-1.0.4-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file logging_singleton-1.0.4.tar.gz.

File metadata

  • Download URL: logging_singleton-1.0.4.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for logging_singleton-1.0.4.tar.gz
Algorithm Hash digest
SHA256 9201423ea044d076e93cc28061b9a6f4e2f5557d888f77453a018932f57fdba8
MD5 3ad87d9c1fda317e72704880db1b42f7
BLAKE2b-256 93fbd3c6b8816f9a6f29abcb453ba2cc1f4294399b2e89a30208077f2ce635cf

See more details on using hashes here.

File details

Details for the file logging_singleton-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for logging_singleton-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b6fbeab32a76def9115bfdbcfb078bfaa8d7ec8d3f80dfe2fe6848c9b8a92658
MD5 a4e0be54b250b595bb3625bd40b93f87
BLAKE2b-256 63df969b17ba88b9576ca0df7016561fb1ebd365b7b0f9e91559f007cd00f460

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