DEV Community

Muhammad Imran Ali Khan
Muhammad Imran Ali Khan

Posted on • Updated on • Originally published at imran-ali.Medium

Easiest Multi-Modular Python Logging

Easy logging with a logging wrapper for Newbies or fast pacers
Do you have a multi-modular python application and want to swiftly enable logging in it?
Are you tired of Initializing logger in your every module and keeping track of it ?
Is your Python logger not working as it is supposed to ?
Do you want different kind of logging happening together with minimal code ?
Do you want to quickly enable logging into your code before wrapping up your progress today ?
If the answer is ‘YES’ to any of the question above then you have come to the right place.
I have written an easy to implement wrapper for you that prevents you from scratching your head for the PETTY yet ANNOYING logging issues that you might encounter.

Let’s Get Started !

Installation

You need to download 2 files from the GitHub repository attached below and place it in your current working folder.
Files : Logger.py with the config logging.conf
Link : Github Repository

Usage

Import the Easy-Logger Wrapper into your Script/Module

import Logger
Enter fullscreen mode Exit fullscreen mode

Then initialize it in the main indent

logger = Logger.Logger("Main Program")
Enter fullscreen mode Exit fullscreen mode

And that’s all. Now you can log your heart out throughout your module using :

logger.debug("Nice My Debug Log Message")
logger.info("Ok My Info Log Message")
logger.warning("Hmm My Warning Log Message")
logger.error("Oops My Error Log Message")
logger.critical("Eeehhh My Critical Log Message")
Enter fullscreen mode Exit fullscreen mode

Advanced Usage

There are two level of details in the Easy-Logger at the moment

  • root
  • brief The level can be changed easily when initializing the module by using the following command
logger = Logger.Logger("Main Program",'brief')

logger = Logger.Logger("Main Program",'root')
Enter fullscreen mode Exit fullscreen mode

Yet To Come..

  • Example Code
  • More level of details handlers in the Easy-Logger
  • Details about modifying the configuration file
  • Logs rotation details
  • Network Logging
  • More Log Formats First of many stories & tutorials to come.. Still getting familiar with the medium and its interface though 😆. Hopefully these will prove worthwhile to the community.

Top comments (0)