Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use log helper #449

Merged
merged 21 commits into from
Mar 29, 2022
Merged

Conversation

christian-intra2net
Copy link
Contributor

This is a much improved version over PR #447

Starting point is the "TODO: use log_helper" in crypto.py. This lead to using log_helper also in olevba which in turn meant making log_helper and olevba's own json-output compatible.

During work on this I realized that some logging output goes to stdout, some to stderr. Fixed that by making stdout the default for all log output.

As decalage noticed: enable_logging functions are required to allow logging output when importing oletools modules from other packages. Added/Updated these for olevba, crypto and record_base. Added a unittest to ensure this works.

@christian-intra2net
Copy link
Contributor Author

I hope it is alright to log to stdout, I am uncertain what the result of our discussions on this topic was. Stdout is just easier because on stderr we would also have to worry about warnings (issued using warnings.warn() which would have to be captured and transformed in json mode

@christian-intra2net
Copy link
Contributor Author

Rebased onto current master

@christian-intra2net
Copy link
Contributor Author

Required a rebase after merging #365

@christian-intra2net
Copy link
Contributor Author

christian-intra2net commented Sep 28, 2021

Rebased to keep up-to-date. Anything I can do to simplify review/merging?

Need something like this for when modules are imported by other modules
(no main in oletools is run, so no log_helper.enable_logging)
So glad we have the unittests, otherwise would never have found this
This is slightly more complicated since olevba has its own json-print
functions that need to be made compatible with log_helper's json formatting
Make log_helper compatible with olevba which has its own print_json
function and does not (yet?) use logging to create json.
Logging uses the default StreamHandler, which per default sends its
output to sys.stderr. However, the surrounding '[', ']' are printed
to stdout. Fix that.
This constant is needed for enable_logging() functions. It is the
only reason for `import logging` in common-logging-enabled modules.
Easier to provide it in log_helper
This is part of LoggerAdapter only since python 3.2
Do not need the last meta-information return code json output from
olevba any more
@christian-intra2net
Copy link
Contributor Author

Rebased onto current master

@decalage2 decalage2 merged commit 89e4dda into decalage2:master Mar 29, 2022
@christian-intra2net
Copy link
Contributor Author

Thanks :)

@christian-intra2net christian-intra2net deleted the use-log_helper branch April 20, 2022 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants