Changeset 7091
- Timestamp:
- May 27, 2009, 8:00:10 AM (16 years ago)
- Location:
- branches/numpy/anuga/utilities
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/numpy/anuga/utilities/log.py
r7088 r7091 7 7 Use it this way: 8 8 import anuga.utilities.log as log 9 log.console_logging_level = log.DEBUG 9 10 # configure my logging 11 log.console_logging_level = log.INFO 12 log.log_logging_level = log.DEBUG 13 log.log_filename('./my.log') 14 15 # log away! 10 16 log.debug('A message at DEBUG level') 11 17 log.info('Another message, INFO level') 12 18 13 19 This class uses the 'borg' pattern - there is never more than one instance 14 of log data. See 20 of log data. See the URL for the basic idea used here: modules *are* 21 singletons! 22 15 23 <http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html> 16 for the basic idea used here: modules *are* singletons!17 24 18 25 Until the first call to log() the user is free to play with the module data 19 26 to configure the logging. 20 27 21 Note that this module uses features of the logging package that were introduced 22 in python2.5. If running on earlier versions, these features are disabled: 28 Note that this module uses some features of the logging package that were 29 introduced in python2.5. If running on earlier versions, the following 30 features are disabled: 23 31 . Calling module name + line number 24 32 ''' … … 59 67 NOTSET = logging.NOTSET 60 68 61 # set new_python to True if python version 2.5 or later 62 (version_major, version_minor, _, _, _) = sys.version_info 63 new_python = ((version_major == 2 and version_minor >= 5) or version_major > 2) 69 # set _new_python to True if python version 2.5 or later 70 _new_python = (sys.version_info >= 0x02050000) # 2.5.x.x 64 71 65 72 … … 89 96 90 97 # setup the file logging system 91 if new_python:98 if _new_python: 92 99 fmt = '%(asctime)s %(levelname)-8s %(mname)25s:%(lnum)-4d|%(message)s' 93 100 else: … … 112 119 logging.getLevelName(log_logging_level), 113 120 logging.getLevelName(console_logging_level))) 114 if new_python:121 if _new_python: 115 122 logging.log(logging.CRITICAL, start_msg, 116 123 extra={'mname': __name__, 'lnum': 0}) … … 133 140 break 134 141 135 if new_python: 142 # why are we here? ... Oh yes! Log the message! 143 if _new_python: 136 144 logging.log(level, msg, extra={'mname': fname, 'lnum': lnum}) 137 145 else: … … 140 148 ## 141 149 # @brief Hook function to process uncaught exceptions. 142 # @param type 143 # @param value 144 # @param traceback 150 # @param type Type of exception. 151 # @param value Exception data. 152 # @param traceback Traceback object. 145 153 # @note Same interface as sys.excepthook() 146 154 def log_exception_hook(type, value, tb): … … 252 260 253 261 test_it() 262 info('sys.version_info=%s, _new_python=%s' 263 % (str(sys.version_info), str(_new_python)))
Note: See TracChangeset
for help on using the changeset viewer.