Changeset 7651 for main/waeup.sirp/trunk/src
- Timestamp:
- 15 Feb 2012, 08:25:58 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/utils
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/utils/logger.py
r7196 r7651 82 82 from waeup.sirp.interfaces import ( 83 83 IDataCenter, IDataCenterStorageMovedEvent, ILoggerCollector) 84 from waeup.sirp.utils.helpers import get_current_principal 84 85 85 86 #: Default logfile size (5 KB) … … 116 117 """ 117 118 119 class ContextFilter(logging.Filter): 120 """ 121 This is a filter which injects contextual information into the log. 122 123 """ 124 125 def filter(self, record): 126 user = get_current_principal() 127 record.user = getattr(user, 'id', 'system') 128 return True 129 118 130 class Logger(object): 119 131 """Mixin-class that for logging support. … … 169 181 dict(sitename='%s' % sitename)) 170 182 logger = logging.getLogger(loggername) 183 flt = ContextFilter() 184 logger.addFilter(flt) 171 185 if site is None or sitename is None: 172 186 # Site not added to ZODB yet. Log to commandline … … 202 216 handler.setLevel(LEVEL) 203 217 formatter = logging.Formatter( 204 '%(asctime)s - %(levelname)s - %( message)s')218 '%(asctime)s - %(levelname)s - %(user)s - %(message)s') 205 219 handler.setFormatter(formatter) 206 220 -
main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_logger.py
r7196 r7651 266 266 logfile = handler.baseFilename 267 267 content = open(logfile, 'rb').read() 268 self.assertTrue(content.endswith(' - INFO - msg from do_something\n'))268 self.assertTrue(content.endswith(' - INFO - system - msg from do_something\n')) 269 269 return 270 270
Note: See TracChangeset for help on using the changeset viewer.