Commit bcc339d68d572b11f711b80d86a3bb9c2c15b0c8
1 parent
de1e1ee6
mraptor: Use log_helper
Logging in mraptor is used for debugging olevba only
Showing
1 changed file
with
6 additions
and
12 deletions
oletools/mraptor.py
| ... | ... | @@ -71,7 +71,7 @@ __version__ = '0.56.2' |
| 71 | 71 | |
| 72 | 72 | #--- IMPORTS ------------------------------------------------------------------ |
| 73 | 73 | |
| 74 | -import sys, logging, optparse, re, os | |
| 74 | +import sys, optparse, re, os | |
| 75 | 75 | |
| 76 | 76 | # IMPORTANT: it should be possible to run oletools directly as scripts |
| 77 | 77 | # in any directory without installing them with pip or setup.py. |
| ... | ... | @@ -90,11 +90,12 @@ from oletools.thirdparty.tablestream import tablestream |
| 90 | 90 | |
| 91 | 91 | from oletools import olevba |
| 92 | 92 | from oletools.olevba import TYPE2TAG |
| 93 | +from oletools.common.log_helper import log_helper | |
| 93 | 94 | |
| 94 | 95 | # === LOGGING ================================================================= |
| 95 | 96 | |
| 96 | 97 | # a global logger object used for debugging: |
| 97 | -log = olevba.get_logger('mraptor') | |
| 98 | +log = log_helper.get_or_create_silent_logger('mraptor') | |
| 98 | 99 | |
| 99 | 100 | |
| 100 | 101 | #--- CONSTANTS ---------------------------------------------------------------- |
| ... | ... | @@ -230,15 +231,7 @@ def main(): |
| 230 | 231 | """ |
| 231 | 232 | Main function, called when olevba is run from the command line |
| 232 | 233 | """ |
| 233 | - global log | |
| 234 | 234 | DEFAULT_LOG_LEVEL = "warning" # Default log level |
| 235 | - LOG_LEVELS = { | |
| 236 | - 'debug': logging.DEBUG, | |
| 237 | - 'info': logging.INFO, | |
| 238 | - 'warning': logging.WARNING, | |
| 239 | - 'error': logging.ERROR, | |
| 240 | - 'critical': logging.CRITICAL | |
| 241 | - } | |
| 242 | 235 | |
| 243 | 236 | usage = 'usage: mraptor [options] <filename> [filename2 ...]' |
| 244 | 237 | parser = optparse.OptionParser(usage=usage) |
| ... | ... | @@ -272,9 +265,9 @@ def main(): |
| 272 | 265 | print('MacroRaptor %s - http://decalage.info/python/oletools' % __version__) |
| 273 | 266 | print('This is work in progress, please report issues at %s' % URL_ISSUES) |
| 274 | 267 | |
| 275 | - logging.basicConfig(level=LOG_LEVELS[options.loglevel], format='%(levelname)-8s %(message)s') | |
| 268 | + log_helper.enable_logging(level=options.loglevel) | |
| 276 | 269 | # enable logging in the modules: |
| 277 | - log.setLevel(logging.NOTSET) | |
| 270 | + olevba.enable_logging() | |
| 278 | 271 | |
| 279 | 272 | t = tablestream.TableStream(style=tablestream.TableStyleSlim, |
| 280 | 273 | header_row=['Result', 'Flags', 'Type', 'File'], |
| ... | ... | @@ -346,6 +339,7 @@ def main(): |
| 346 | 339 | global_result = result |
| 347 | 340 | exitcode = result.exit_code |
| 348 | 341 | |
| 342 | + log_helper.end_logging() | |
| 349 | 343 | print('') |
| 350 | 344 | print('Flags: A=AutoExec, W=Write, X=Execute') |
| 351 | 345 | print('Exit code: %d - %s' % (exitcode, global_result.name)) | ... | ... |