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

Capture warnings into log-helper #799

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

christian-intra2net
Copy link
Contributor

Warnings can mess-up the output of oletools, a recent example is the Deprecation Warning of cryptography for python2. Human readers have no trouble ignoring these but automated tests or other tools that use oletools in a pipeline, in particular with json-formatted output, get into trouble.

However, python offers a solution, which is logging.captureWarnings. By enabling this, the log-helper can deal with unexpected warnings.

Encountered an example where a 3rd-party library issued a warning that
messed up the json output. Create test to reproduce this.
We set logging.captureWarnings to True and use our logging framework for
python's builtin warnings logger. Warnings from that logger will have
"type=warning" per default (as opposed to "type=msg").
Warning message includes source file and line number, hope this is not
dependent on python version..
Need to make sure that json output is formatted since e.g. warning messages
are created like this:
   log.warning('%s', actual_message)
so without proper formatting the message is just "%s".

Also test that exception info is added as usual.
Use a standard logging.Formatter to do %-formatting and other stuff (i.e.
the regular formatter job) before converting to Json.
If there is an error in log-handling (e.g. wrong args to logger call) do
not fail or raise but produce something helpful
@decalage2 decalage2 self-requested a review May 30, 2024 19:42
@decalage2 decalage2 self-assigned this May 30, 2024
@decalage2 decalage2 added this to the Next Release milestone Jun 10, 2024
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