comparison MoinMoin/log.py @ 3165:b8dc6c2e6c53

integrate MoinMoin.support.logging_fix into MoinMoin.log
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 02 Mar 2008 02:19:42 +0100
parents dc182f4936b1
children aae4a2384804
comparison
equal deleted inserted replaced
3164:c25bc6e9ad61 3165:b8dc6c2e6c53
20 This will create a logger with 'MoinMoin.your.module' as name. 20 This will create a logger with 'MoinMoin.your.module' as name.
21 The logger can optionally get configured in the logging configuration. 21 The logger can optionally get configured in the logging configuration.
22 If you don't configure it, some upperlevel logger (e.g. the root logger) 22 If you don't configure it, some upperlevel logger (e.g. the root logger)
23 will do the logging. 23 will do the logging.
24 24
25 @copyright: 2008 MoinMoin:ThomasWaldmann 25 @copyright: 2008 MoinMoin:ThomasWaldmann,
26 2007 MoinMoin:JohannesBerg
26 @license: GNU GPL, see COPYING for details. 27 @license: GNU GPL, see COPYING for details.
27 """ 28 """
28 29
29 # This is the "last resort" fallback logging configuration for the case 30 # This is the "last resort" fallback logging configuration for the case
30 # that load_config() is either not called at all or with a non-working 31 # that load_config() is either not called at all or with a non-working
66 format=%(asctime)s %(levelname)s %(name)s:%(lineno)d %(message)s 67 format=%(asctime)s %(levelname)s %(name)s:%(lineno)d %(message)s
67 datefmt= 68 datefmt=
68 class=logging.Formatter 69 class=logging.Formatter
69 """ 70 """
70 71
71 from MoinMoin.support import logging_fix
72 import logging, logging.config 72 import logging, logging.config
73 73
74 configured = False 74 configured = False
75 fallback_config = False 75 fallback_config = False
76 76
112 for levelnumber, levelname in logging._levelNames.items(): 112 for levelnumber, levelname in logging._levelNames.items():
113 if isinstance(levelnumber, int): # that list has also the reverse mapping... 113 if isinstance(levelnumber, int): # that list has also the reverse mapping...
114 setattr(logger, levelname, levelnumber) 114 setattr(logger, levelname, levelnumber)
115 return logger 115 return logger
116 116
117
118 # Python 2.3's logging module has no .log, this provides it:
119 if not hasattr(logging, 'log'):
120 def log(level, msg, *args, **kwargs):
121 if len(logging.root.handlers) == 0:
122 logging.basicConfig()
123 if logging.root.manager.disable >= level:
124 return
125 if level >= logging.root.getEffectiveLevel():
126 logging.root._log(level, msg, args, **kwargs)
127 logging.log = log
128