Skip to main content

An extension for standard python logging

Project description

py_logging_extensions

a wrapper to provide advanced logging capability with a simple call

Provides:

  • coloured logging (If colorama installed)
  • Log to file
  • configuration file is generated for log formats and colours
  • different log format for levels of logging.DEBUG and below
  • TRACE logging level added as a level below logging.DEBUG (set to 5)

Basic Usage

    import logging

    # Import and setup the logger
    from log_ext import setup_logger
    setup_logger()

    # Create a normal logging instance, and use as per normal docs
    logger = logging.getLogger('ExampleLogger')
    logger.setLevel(logging.DEBUG)
    logger.debug('MyDebugMessage')

setup_logger

setup_logger(
    name='log',
    base_logger=None,
    log_dir='logs',
    cfg_file='log.yaml',
    config={
        'date_fmt_str': '%Y-%m-%d_%H:%M:%S',
        'format_str': '%(asctime)17s-%(name)-12s-%(levelname)-8s-%(message)s',
        'detailed_format_str': '(%(module)s-%(funcName)s #%(lineno)d)',
        'colors': {
            'TRACE': 'Back.WHITE,Fore.BLACK',
            'DEBUG': 'Fore.CYAN',
            'INFO': 'Fore.GREEN', 
            'WARNING': 'Fore.YELLOW', 
            'ERROR': 'Fore.RED', 
            'CRITICAL': 'Back.RED,Fore.WHITE'
        }
    },
    trace_logging=True,
    clear_others=False,
    handles=None)

Setup a logger (call instead of logging.basicConfig)

:param name: (String) log file name
:param base_logger: (logging.Logger) logger to base off - uses root if not set
:param log_dir: (string | False) directory to store log files in - doesn't log to file if set to False
:param cfg_file: (string | False) configuration file to use, or false to skip creating a file
:param config: (Dict) configuration dictionary see CONFIG variable for example
:param trace_logging: (Bool) use trace logging
:param clear_others: (Bool) clear existing handlers on the base logger
:param handles: (List) also add these handlers to the base logger
:returns None

Notes

Pyinstaller

If using pyinstaller, make sure to provide paths suitable for your install path for log_dir and cfg_file - if you are using them.

clearing handlers

set clear_others to true to clear any existing handlers.

Log file

set log_dir to false to avoid logging to file.

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

log_ext-1.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

log_ext-1.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file log_ext-1.1.0.tar.gz.

File metadata

  • Download URL: log_ext-1.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.3

File hashes

Hashes for log_ext-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7df42efe37a1089b6e5c9f237512673695b8eef882acf46f49f8c515d9127f07
MD5 a80d58477413a570a4b0ca8746de5684
BLAKE2b-256 106bf62d058436f9ceecbc399e1393d2309ec142fe405945460732386627da2e

See more details on using hashes here.

File details

Details for the file log_ext-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: log_ext-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.3

File hashes

Hashes for log_ext-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1ca4d4cdfcebc9620ec727dd4d4bddb30f202b6872f3af4553faff1b223695d
MD5 a1a9eb485abfbf158bd58c85ea1305c5
BLAKE2b-256 7a131d4a3dd8b6535f840b4e3924190fa7a0a8fbe5e3d80bd2cdb6153bbe63e0

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