|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /proc/21573/root/usr/lib/python2.4/site-packages/setroubleshoot/ |
Upload File : |
mò 3ÔUc @ s d Z d d d d d d d d g Z d k Z d k Z d k Z d k Z d k Z d k Td k Te a h Z h Z h Z e i Z e i a e a e a e i ƒ Z d d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z e e d „ Z d d „ Z d „ Z! d S( sŽ The python logging module gives us loggers and handlers, sometimes that's a bit obscure, we rename this concepts to be more friendly: loggers --> log_categories handlers --> log_output loggers are organized in a tree structure with a single root logger. handlers may be attached to to any logger in the logger tree (for example if you wanted to direct output from one category to a specific place). When a handler wishes to output it walks the tree up to the root calling each handler it finds. For simplicity sake by default we attach all our handlers to the root logger. Thus all the output handlers have equal opportunity to output a logging message from one of the loggers. Messages may be filtered by specifying a level. There are 3 places a level may be set: 1) on the logger 2) on the handler 3) on the root logger (special case of item 1, global level) A message has a level attached to it. The decision process of when to emit a message works like this: 1) The path in the logger tree is walked from the logger to the root logger. The first logger encountered with a level other than NOTSET defines the effective level, if the message level is greater than or equal to the effective level it is accepted for output. If only NOTSET is found this becomes the effective level and the message is accepted for output. 2) If the message passes the logging (category) level test then every logger in the path from the logger to the root logger is given an opportunity to emit the message by iterating over its list of output handlers. If the message level is greater than or equal to tbe level of the output handler it is output. One consequence of this is that if an output handler is bound to both the category logger and the root logger it will be emitted twice. However, if you bind distinct output loggers to tbe category logger and the root logger then each output logger may have its own level and destination. Note: the logging modules provides for propagation flags which stop traversal to the root as well as filters for more complex filtering then simple level testing, this offers more fine grained control. Thus for a message to be output it must: 1) first pass the level test for the logging category. 2) secondly also pass the level test for every output handler bound to every level in the path from the logger to the root. It is tempting to want to set the global level on the root logger and default the level on any category logger to NOTSET. This would cause the root logger's level to take effect for any category logger without an explicit level (e.g. the root logger is the default global level). The notion of inheriting a level from your ancestors is nice, but in practice its difficult to meet expectations using level inheritance, instead we set a level on every logger and forego inheritance, here's why: If the root level was higher than an explicitly set category level the message would be filtered. This would be counter to the expectation if an explict level was set for any category it would be respected and would be output. To get around this one could set the level on the root logger to pass everything (e.g. NOTSET). This would allow explicitly set category levels to be respected. However, if a category did not have an explicit level set it would default to NOTSET which would pass the message to the root, which being NOTSET would pass the message to all of its output handlers. The effect would be any category without an explicit level set would always output, this also is not what is expected. The solution is not to try and set the default global level on the root logger and depend on inheritance, but rather explicitly set the level of every logger, either to the level requested for that category, or to the default global level if an explicit level is absent for the category. Why is there a global debug flag that is checked before any call to log_xxx.debug()? The logger.debug() function will check the levels and not output anything if the level settings would prohibit the debug message, clearly the debug flag is unnecessary, right? This is true, however, if one considers the amount of work the logging library does just to determine the log message will be discarded and observe that in most all cases debug logging will be turned off this consititues a performance hit, especially considering the large number of logger.debug() calls throughout the code. In 'C' or similar languages one could use preprocessor macros to eliminate debug logging in production code, but this option is not available in python so we wrap all logger.debug() calls in an 'if debug:' test to prevent spending cycles on an operation which will be thrown away. Having a global debug flag does require reevaluatiing it anytime the level of any logging category changes because if any category is set for debug logging the flag must be true so the loggers can be given a chance to evaluate the message for their category. t log_initt debugt profilet set_default_category_levelt set_category_levelt enable_log_outputt set_log_output_levelt dump_log_levelsN( t *c C s“ t o d Sn t a t d d ƒ } d | } t i t i ƒ yY t i i d d ƒ } | i t i ƒ | t d <t i | ƒ } | i | ƒ t d ƒ Wn0 t j o$ } t i d | IJd t d <n Xt i i | ƒ } d | } t t | d d | ƒ ƒ a t | d d | ƒ } t | d d | ƒ } t | d d | d ƒ } t | d d i# t$ ƒ | ƒ } t | d t&