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

remove color from log files #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions better_exceptions/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys

from logging import Logger, StreamHandler
from logging import Logger, StreamHandler, FileHandler


def patch():
Expand All @@ -14,7 +14,8 @@ def patch():
if hasattr(logging, '_defaultFormatter'):
logging._defaultFormatter.format_exception = logging_format_exception

patchables = [handler() for handler in logging._handlerList if isinstance(handler(), StreamHandler)]
patchables = [handler() for handler in logging._handlerList if isinstance(handler(), StreamHandler)
if not isinstance(handler(), FileHandler)]
Comment on lines +17 to +18
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
patchables = [handler() for handler in logging._handlerList if isinstance(handler(), StreamHandler)
if not isinstance(handler(), FileHandler)]
patchables = [
handler() for handler in logging._handlerList
if (
isinstance(handler(), StreamHandler) and
not isinstance(handler(), FileHandler)
)
]

Copy link
Owner

Choose a reason for hiding this comment

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

Let's see if this works still, as it's a bit clearer to read.

patchables = [handler for handler in patchables if handler.stream == sys.stderr]
patchables = [handler for handler in patchables if handler.formatter is not None]
for handler in patchables:
Expand Down
29 changes: 29 additions & 0 deletions test/output/python2-dumb-UTF-8-color.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
 └ 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-dumb-UTF-8-nocolor.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
└ 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-dumb-ascii-color.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
 -> 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-dumb-ascii-nocolor.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
-> 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-vt100-UTF-8-color.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
 └ 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-vt100-UTF-8-nocolor.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
└ 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-vt100-ascii-color.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
 -> 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-vt100-ascii-nocolor.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
-> 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-xterm-UTF-8-color.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
 └ 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-xterm-UTF-8-nocolor.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
└ <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
└ 52
AssertionError: assert baz == 90




29 changes: 29 additions & 0 deletions test/output/python2-xterm-ascii-color.out
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ SyntaxError: invalid syntax



python2 test/test_file_without_colors.py


INFO:__main__:Hello
INFO:__main__:Hello
NoneType

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar3 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 36, in bar3
raise Exception('this is a test exception')
Exception: this is a test exception

ERROR:__main__:callback failed
Traceback (most recent call last):
File "test/test_file_without_colors.py", line 19, in foo
cb()
-> <function bar4 at 0xDEADBEEF>
File "test/test_file_without_colors.py", line 41, in bar4
assert baz == 90
 -> 52
AssertionError: assert baz == 90




Loading