Is it possible to have different level names for different handlers in Python Logging -


In Python 2.6 (and later on versions, but I'm looking at just 2.6), it appears that the lale name of the logging module (

  _levelNames = {CRITICAL: 'CRITICAL', error: 'error', warning: 'warning', info: 'INFO', Warning: 'Notice': Notice, 'Debug': Debug, 'Not Notice:' Notice ',' Critical ': Serious,' Error ': Error,' Warne ': Chet The module provides a way to override these names:  
  Def addLevelName (level, levelName): "" "with associate 'level name' 'level'. This message is used when converting levels in text during formatting." "_acquireLock () Try: # There is a possibility to do this, but you never know ... _levelNames [level] = levelName _levelNames [levelName] = level at the end: _releaseLock ()   

but this is a On a global basis.

I need to enter syslog so that ERR or log messages are tagged "Head" and warning log message tags are "MINOR".

Now using the addLevelName () method is easy to rename, but then, it is on a global basis. I want to use my syslog handler to be Major and Minor but want to leave error and warning for program logs. I do not have to do exactly this and can live with global names, but I did not want to be on all source code and I could not find a hook which let me do this.

Am I missing something?

You can use a custom formatter on the appropriate code < Code> Level name to LogRecord will not make any global changes to the level names you want:

  class MyFormatter (logging.former ): Def format (self, record): if record.levelname == 'ERROR': record Levelname = 'MAJOR' elif record.levelname == 'WARNING': record.levelname = 'MINOR' result = super (MyFormatter, self ) .format (record) if record.levelname == 'MAJOR': record.levelname = 'error' alif D. LevelName == 'MINOR': record.levelname = 'WARNING' return result    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -