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

Add STDERR argument, and write docs for args module #760

Merged
merged 11 commits into from
Oct 11, 2016

Conversation

zachriggle
Copy link
Member

@zachriggle zachriggle commented Oct 7, 2016

This should make it so that anybody can choose where the logs go without needing to set it every time.

#!/usr/bin/python2
from pwn import *

log.info('before')
pwnlib.log.console.stream = sys.stderr
log.info('after')
$ ./foo.py
[*] before
[*] after
$ ./foo.py > /dev/null
[*] after
$ ./foo.py STDERR > /dev/null
[*] before
[*] after
$ export PWNLIB_STDERR=1
$ ./foo.py >/dev/null
[*] before
[*] after
$ ./foo.py 2>/dev/null
# <nil>

Fixes #759

@@ -663,8 +663,6 @@ def install_default_handler():
the ``pwnlib`` root logger. This function is automatically called from when
importing :mod:`pwn`.
'''
console.stream = sys.stdout
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that this is superfluous, since we instantiate console with sys.stdout as its stream just a few lines above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually superfluous, it causes tests to fail. Wat.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was accidentally keeping our unit-tests from breaking by re-invoking install_default_handler() for each module's doctests. The root-cause is pwnlib.commandline.common was setting it to stderr, which should only happen when main() is invoked, not when the module is imported.

@zachriggle
Copy link
Member Author

The tests are breaking because the command-line programs are generating doctests, which change the log to stderr.

@zachriggle
Copy link
Member Author

CI passes, I'm choosing to ignore the Codacy issue since I'm not sure how to resolve it (you can't have properties on classmethod).

@zachriggle zachriggle merged commit f9133b1 into Gallopsled:dev Oct 11, 2016
@zachriggle zachriggle added this to the 3.3.0 milestone Oct 11, 2016
@zachriggle zachriggle self-assigned this Oct 11, 2016
@zachriggle zachriggle deleted the log-stderr-args branch October 11, 2016 02:14
Kyle-Kyle pushed a commit to Kyle-Kyle/pwntools that referenced this pull request Apr 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant