Skip to main content

python logging extensions supporting additional levels, colorization and more

Project description

pylogx

python logging extensions supporting additional levels, colorization, indentation and more

Features

  • Additional log levels (HINT, NOTE, TRACE) for more granularity
  • Colorize log messages based on the log level
  • Indent log messages
  • Log relative time stamps

Quickstart

Colorize your log messages

    import time
    from pylogx import log, ColoredFormatter

    console = logging.StreamHandler()
    cf = ColoredFormatter(fmt="%(prettyDelta)s [%(prettyRelativeDelta)s] %(indent)s %(message)s",
                          ups=[Level.NOTE]) 
    console.setFormatter(cf)
    console.setLevel(Level.NOTE)
    log.addHandler(console)

    log.trace("Have fun with colorized log messages")
    log.note("This message disappears with the next log message")
    time.sleep(5)
    log.note("Another message disappearing soon..")
    time.sleep(5)
    log.info("Last message is gone")

Indent your log messages

    from pylogx import log, IndentFilter

    formatter = logging.Formatter(fmt="%(asctime)s %(indent)s%(message)s")
    log.setFormatter(formatter)

    iflt = IndentFilter()
    log.addFilter(iflt)

    log.info("base level")

    iflt.inc()
    log.info("sub level")

    iflt.inc()
    log.info("sub sub level")

    iflt.dec()
    log.info("sub level")

    iflt.dec()
    log.info("base level")

Print log messages with relative time stamp

    import logging
    from pylogx import log, PrettyDelta

    pd = PrettyDelta()
    log.addFilter(prettyDelta)
    prd = PrettyDelta(name="prettyRelativeDelta", fmt="+%M:%S.%f", relative=True)
    log.addFilter(prd)
    formatter = logging.Formatter(fmt="%(prettyDelta)s [%(prettyRelativeDelta)s] %(indent)s %(message)s")
    log.setFormatter(formatter)
    log.message("enjoy relative timestamps)

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

pylogx-0.1.1.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

pylogx-0.1.1-py2.py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page