Search This Blog

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Monday, June 16, 2014

Python- Logging Architecture

Python Logging module helps in logging to multiple destination handlers.

It has a very simper architecture as below : -

(1)  Logger,LogObject,Handler and Formatter are the main Actor of this architecture.

(2) There are in total 5 types of severity Levels as defined below with severity in ASCENDING order: -
DEBUG
INFO
WARNING
ERROR
CRITICAL

(3) Logger,Handlers has severity levels

(4) Logger generally inspects the message and does the below 2 operation : -
   
     (4.1)Ignores the message if the message is less severe than the Logger

   (4.2) Otherwise creates LogRecord object from message and passes it to Handler.




(5) Handler responsible for the following 2 tasks : -
  • Outputs message - to a file, stream, socket or where ever you want it to go. You can add a Handler to the Logger by using the addHandler method of the Logger.
  • The Handler also has a level. Once the Handler receives the LogRecord from the Logger, it will ignore any LogRecord that has a severity level that is smaller than its own level. Otherwise it passes the LogRecord to its Formatter

 (6) Each Handler has one Formatter (which you can customize to your taste). The Formatter formats the LogRecord message to the desired format and sends the formatted text back to the Handler.


Putting It All Together :



Thanks . I hope it helps ;)