Giter VIP home page Giter VIP logo

litelog's Introduction

LiteLog

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
from LiteLog 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(...)

litelog's People

Watchers

James Cloos avatar Matthew Cotton avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.