Skip to main content

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.

Release files for log-ext 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for log-ext 1.1.0
File Size Uploaded
log_ext-1.1.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for log-ext 1.1.0
File Interpreter ABI Platform
log_ext-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.7 kB

Release files / log_ext-1.1.0.tar.gz

Download URL log_ext-1.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7df42efe37a1089b6e5c9f237512673695b8eef882acf46f49f8c515d9127f07
BLAKE2b-256 checksum
How to use checksums
106bf62d058436f9ceecbc399e1393d2309ec142fe405945460732386627da2e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / log_ext-1.1.0-py3-none-any.whl

Download URL log_ext-1.1.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1ca4d4cdfcebc9620ec727dd4d4bddb30f202b6872f3af4553faff1b223695d
BLAKE2b-256 checksum
How to use checksums
7a131d4a3dd8b6535f840b4e3924190fa7a0a8fbe5e3d80bd2cdb6153bbe63e0
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page