Skip to main content

Simplified, robust, selective, recursive logging utility for Python.

Project description

LiteLog is an easy-to-use, totally standard-library Python logging utility that makes complex logging functions easy.

Features

  • automatically-named per-file logfiles, specifically written next to the source files.

  • special __debug__ log, where tagged functions can have all of their input/output/errors safely reported completely transparently and without interference.

  • different log message levels, just like the ‘logging’ builtin.

  • recursive calls in __debug__ are indented, so determining function call depth is natural.

Installation

To install globally, run:

sudo pip install litelog

To install locally (such as within a virtual environment), run:

pip install litelog

Usage

The following is copy-and-pasteable code, so long as litelog is available globally:

####################################
# SETTING UP THE LOGGER
import os
import litelog
ROOTPATH = os.path.splitext(__file__)[0]
LOGPATH = "{0}.log".format(ROOTPATH) # this simply specifies the absolute path -- feel free to change this.
LOGGER = litelog.get(__name__, path=LOGPATH)
LOGGER.info("----------BEGIN----------")

# do the following step if you want
# a global 'debug' log file:
litelog.set_debug(__file__)
####################################

When pasted at the top of your program, the above lines:

  • create a logger specifically for the current file, with the same name (ex: test.py -> test.log)

  • add a starting line/delimiter to the log, to indicate separate module imports/runs (by default, the logs are appended to)

  • creates an optional global “debug” logger, which can record the I/O/Errors of any function tagged with ‘@litelog.logwrap’ (set_debug() should only be called once)

Here are the actual use case examples:

@litelog.logwrap # <--- do this if you want a __debug__.log to record I/O/Error of function calls
def f():
    ...
    LOGGER.info('just a test') # <--- do this if you want to log custom
                               #      messages to the script's personal log.

####################################
# logging levels:
LOGGER.debug   (...)
LOGGER.info    (...)
LOGGER.warning (...)
LOGGER.error   (...)
LOGGER.critical(...)

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

litelog-0.2.6.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file litelog-0.2.6.tar.gz.

File metadata

  • Download URL: litelog-0.2.6.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for litelog-0.2.6.tar.gz
Algorithm Hash digest
SHA256 f703ce9449a5233019f10cecdb1495c07f709ab50b0d036aef0730f5fe999687
MD5 03370e03c9e0ee7cc93df0a5572a3ac1
BLAKE2b-256 af8f5502d2e1ba5ad2efb57fd93d3e3acfd8fc4ef2d11c2e1312b190ed763779

See more details on using hashes here.

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