Giter Site home page Giter Site logo

jplogger's Introduction

What is jpLogger ?

This is only a wrapper of the logging library from the Python standard library. It aims to provide an easy way to get a mechanism to log messages, errors, and so on. This is a personal implementation that fits a frequent need that I have every time I work on a Python project. It also might fit other users' needs, so that is why I decided to make it public.

What does it include?

  • It is a class (inherited from the logging library of the Python standard library), so the instance can be passed to any place as needed.
  • A console logging handler to show logs in the console as if they were print statements.
  • A rotating log file: This means that you can store more than one log file (the latest log), and every time a new one is created, the rotating file handler will shift the current (latest one) to be the .1 extension and so son.
  • Maximum file size can be set so that the rotating file system will automatically create a new one once the current reaches the maximum size.
  • A logging format already set that fits almost every need.

What does an output file look like?

2022-04-15 02:09:42,474 [tickCount: 474] [MainProcess 19636] [MainThread 4312] - DEBUG __init__ - Logger CMD handler has been initialized successfully!
2022-04-15 02:09:42,493 [tickCount: 493] [MainProcess 19636] [MainThread 4312] - DEBUG __init__ - Logger FILE handler has been initialized successfully!
2022-04-15 02:09:42,493 [tickCount: 493] [MainProcess 19636] [MainThread 4312] - DEBUG __init__ - Logger has been initialized successfully!
2022-04-15 02:09:42,494 [tickCount: 494] [MainProcess 19636] [MainThread 4312] - INFO <module> - Demo Logger
2022-04-15 02:09:42,494 [tickCount: 494] [MainProcess 19636] [MainThread 4312] - DEBUG <module> - Demo Logger
2022-04-15 02:09:42,495 [tickCount: 495] [MainProcess 19636] [MainThread 4312] - WARNING <module> - Demo Logger
2022-04-15 02:09:42,496 [tickCount: 496] [MainProcess 19636] [MainThread 4312] - ERROR <module> - Demo Logger
2022-04-15 02:09:42,499 [tickCount: 499] [MainProcess 19636] [MainThread 4312] - CRITICAL <module> - Demo Logger

How to use it.

If you add this repository as a submodule of your project.

  1. Add this repository as a submodule by running:
git submodule add https://github.com/jjjpolo/jpLogger ./jpLogger
  1. Import the script (use the following example since jpLogger.py will be located in a subdirectory):
from jpLogger.jpLogger import *
  1. Create a jpLogger instance.
# Using default values:
demoLogger = jpLogger()

# A jpLogger instance with custom values:
demoLogger = jpLogger(appName="demo", logFileName = "demo.log", logLevel=logging.INFO, mode=displayMode.cmdAndLog, maxFiles=5, maxFileSize=5*1024*1024)
  1. Printing logs.
demoLogger.info("Demo Logger")
demoLogger.debug("Demo Logger")
demoLogger.warning("Demo Logger")
demoLogger.error("Demo Logger")
demoLogger.critical("Demo Logger")

If you copy the script next to your project.

  1. Import this script from your project.
from jpLogger import *
  1. Create a jpLogger instance.
# Using default values:
demoLogger = jpLogger()

# A jpLogger instance with custom values:
demoLogger = jpLogger(appName="demo", logFileName = "demo.log", logLevel=logging.INFO, mode=displayMode.cmdAndLog, maxFiles=5, maxFileSize=5*1024*1024)
  1. Printing logs.
demoLogger.info("Demo Logger")
demoLogger.debug("Demo Logger")
demoLogger.warning("Demo Logger")
demoLogger.error("Demo Logger")
demoLogger.critical("Demo Logger")

Release notes.

[V1.1]

  • jpLogger is now an inherited class from logging (from the Python standard library)
  • It is compatible with V1.0.

[V1.0]

  • It is a wrapper class of logging (from the Python standard library).
  • It aims to be an easier and faster way of creating logging mechanisms.
  • It offers the user the creation of either console, file or both handlers.

References

In case you need more info about Logging and its handlers in Python.

jplogger's People

Contributors

jjjpolo avatar

Watchers

 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.