Python logging for non-trivial uses? -


I'm trying to use Python logging module to do complex things. I will leave the inspiration for this design because it will make the post too long, but I need to be a root logger which requires a regular log file for our code and library that uses logging - The other logger collections for different log files.

The overall setup should look like this. To simplify the code, I will do everything on stdout in this example. Import logging, sys root = logging.getLogger ('') top = logging.getLogger ('top') = logging down .getLogger ('top.bottom') class KillFilter (object)

: DF filter (auto, message): return 0 root_handler = logging.streamhandler (sys.stdout) top_handler = logging.StreamHandler (sys.stdout) bottom_handler = logging.StreamHandler (Sys.stdout) root_handler.setFormatter (logging.former (' Root ')) top_handler.setFormatter (logging.former (' top handler ')) bottom_handler.setFormatter (logging.former ("botim handler")) msg_killer = KillFilter () Root.addHandler (root_handler) top.addHandler (top_handler) bottom .addHandler (bottom_handler) top.addFilter (msg_killer) root.error ('hi') top.error (' Hi ') below. Terror ('Hi')

This output

  root bottom handler root   

Do not require second hand handler call because according to the logging documentation msg_k the incompetent will stop the message from going to the root logger. Obviously, documentation can use improvements.

EDIT: Removed harsh words "in the moment" for dragon logging. Firstly, I get a different output on my machine (Python 2.6 is running):

    > Root Bottom Handler Top Handler Route  

The filtering applies only to the logger that is issued to the message, and if this filter passes, then it will take all the handlers of the parent logger Promotes (and not the logger itself) - I do not know the logic for this decision. If you want to stop the promotion on the set "Top" logger example, set:

  top.propagation = False  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -