Commit 410baa02e19003765c3338f6aa7753aefc8d18f8
1 parent
bcc339d6
log_helper: Add short usage instruction
Showing
1 changed file
with
23 additions
and
0 deletions
oletools/common/log_helper/log_helper.py
| ... | ... | @@ -3,6 +3,26 @@ log_helper.py |
| 3 | 3 | |
| 4 | 4 | General logging helpers |
| 5 | 5 | |
| 6 | +Use as follows: | |
| 7 | + | |
| 8 | + # at the start of your file: | |
| 9 | + # import logging <-- replace this with next line | |
| 10 | + from oletools.common.log_helper import log_helper | |
| 11 | + | |
| 12 | + logger = log_helper.get_or_create_silent_logger("module_name") | |
| 13 | + def enable_logging(): | |
| 14 | + '''Enable logging in this module; for use by importing scripts''' | |
| 15 | + logger.setLevel(log_helper.NOTSET) | |
| 16 | + imported_oletool_module.enable_logging() | |
| 17 | + other_imported_oletool_module.enable_logging() | |
| 18 | + | |
| 19 | + # ... your code; use logger instead of logging ... | |
| 20 | + | |
| 21 | + def main(): | |
| 22 | + log_helper.enable_logging(level=...) # instead of logging.basicConfig | |
| 23 | + # ... your main code ... | |
| 24 | + log_helper.end_logging() | |
| 25 | + | |
| 6 | 26 | .. codeauthor:: Intra2net AG <info@intra2net>, Philippe Lagadec |
| 7 | 27 | """ |
| 8 | 28 | |
| ... | ... | @@ -71,6 +91,9 @@ DEFAULT_MESSAGE_FORMAT = '%(levelname)-8s %(message)s' |
| 71 | 91 | |
| 72 | 92 | |
| 73 | 93 | class LogHelper: |
| 94 | + """ | |
| 95 | + Single helper class that creates and remembers loggers. | |
| 96 | + """ | |
| 74 | 97 | |
| 75 | 98 | #: for convenience: here again (see also :py:data:`log_helper.NOTSET`) |
| 76 | 99 | NOTSET = logging.NOTSET | ... | ... |