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