2017-09-26 7 views
0

ランタイム時にログを更新してサポートするにはexc_infoキー?exc_infoを使用したlog.exceptionエラー

例:

log.exception(e, exc_info = 1) 

リターンエラー:

TypeError: exception() got an unexpected keyword argument 'exc_info' 

これはPythonである2.6.6

答えて

0

exception方法は、例外のロギングが望まれる例外節から呼び出されることを意味するためexc_infoを受け入れていない単一のメソッド(すなわちexc_infoが暗黙的に設定されます)。 exc_infoFalseに設定した場合と同じ効果を得たい場合は、exceptionメソッドではなく、errorロガーメソッドを使用してください。 the documentationから:

Logger.error(msg, *args, **kwargs)

Logs a message with level ERROR on this logger. The arguments are interpreted as for debug().

...

Logger.exception(msg, *args, **kwargs)

Logs a message with level ERROR on this logger. The arguments are interpreted as for debug(). Exception info is added to the logging message. This method should only be called from an exception handler.

0

使用トレースバック https://docs.python.org/2/library/traceback.html

トレースバックが例外とスタックを出力します

exceの原因となったコードを示すトレースption

import traceback 
_traceback = traceback.format_exc() 
print _traceback 
log.exception(_traceback) 
関連する問題