Commit d2920ad45c4208417be0eee8965d1bc926f4cb2d

Authored by Christian Herdtweck
1 parent 5d7a6445

oleobj: improve logging slightly

Showing 1 changed file with 7 additions and 3 deletions
oletools/oleobj.py
... ... @@ -106,7 +106,8 @@ LOG_LEVELS = {'debug': logging.DEBUG,
106 106 'info': logging.INFO,
107 107 'warning': logging.WARNING,
108 108 'error': logging.ERROR,
109   - 'critical': logging.CRITICAL}
  109 + 'critical': logging.CRITICAL,
  110 + 'debug-olefile': logging.DEBUG}
110 111  
111 112  
112 113 class NullHandler(logging.Handler):
... ... @@ -273,7 +274,7 @@ def guess_encoding(data):
273 274 for encoding in 'ascii', 'latin1', 'utf8', 'utf-16-le', 'utf16':
274 275 try:
275 276 result = data.decode(encoding, errors='strict')
276   - log.debug(u'encoded using {0}: "{1}"'.format(encoding, result))
  277 + log.debug(u'decoded using {0}: "{1}"'.format(encoding, result))
277 278 return result
278 279 except UnicodeError:
279 280 pass
... ... @@ -502,7 +503,8 @@ def find_ole_in_ppt(filename):
502 503 except IOError:
503 504 log.warning('Error reading data from {0} stream or '
504 505 'interpreting it as OLE object'
505   - .format(stream.name), exc_info=True)
  506 + .format(stream.name))
  507 + log.debug('', exc_info=True)
506 508 finally:
507 509 if ole is not None:
508 510 ole.close()
... ... @@ -737,6 +739,8 @@ def main(cmd_line_args=None):
737 739 format='%(levelname)-8s %(message)s')
738 740 # enable logging in the modules:
739 741 log.setLevel(logging.NOTSET)
  742 + if options.loglevel == 'debug-olefile':
  743 + olefile.enable_logging()
740 744  
741 745 # remember if there was a problem and continue with other data
742 746 any_err_stream = False
... ...