ロギングを以下のように設定しました
import logging
logging.basicConfig(
level = logging.DEBUG,
format = '%(asctime)s %(levelname)s %(message)s',
)
logger = logging.getLogger('myapp.views')
def my_view(request):
...
try:
parse_file_using_regex(file):
...
except IndexError as ie:
logger.debug('content of file not proper:',ie)
except ValueError as ve:
logger.debug('caused value error')
valuErrorが発生すると、次の出力が得られます
...Traceback (most recent call last):
File "/usr/lib/python2.6/logging/__init__.py", line 768, in emit
msg = self.format(record)
File "/usr/lib/python2.6/logging/__init__.py", line 648, in format
return fmt.format(record)
File "/usr/lib/python2.6/logging/__init__.py", line 436, in format
record.message = record.getMessage()
File "/usr/lib/python2.6/logging/__init__.py", line 306, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
....Traceback (most recent call last):
File "/usr/lib/python2.6/logging/__init__.py", line 768, in emit
msg = self.format(record)
File "/usr/lib/python2.6/logging/__init__.py", line 648, in format
return fmt.format(record)
File "/usr/lib/python2.6/logging/__init__.py", line 436, in format
record.message = record.getMessage()
File "/usr/lib/python2.6/logging/__init__.py", line 306, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
2012-06-21 09:13:47,909 DEBUG caused value error
誰かが私がこれを理解するのを手伝ってくれる?TypeErrorが発生するのはなぜですか?
pdbを使用し、python2.6 / logging /init.pyに次のものをgetMessage(self)
含めます
import pdb
pdb.set_trace()
print msg,sef.args
...> /usr/lib/python2.6/logging/__init__.py(307)getMessage()
-> print msg,sef.args
(Pdb) msg
'parsing subtitle file:'
(Pdb) self.args
('/home/me/dev/python/django/myapp/media/testpath/testfile.srt',)
(Pdb)