-
Notifications
You must be signed in to change notification settings - Fork 4
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
Added log output trim #157
Conversation
Pull Request Test Coverage Report for Build 3437739245
💛 - Coveralls |
security/utils.py
Outdated
if len(value) <= max_length: | ||
return value | ||
|
||
truncated_value = value[len(value) + 2 - (max_length):] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+2 is added because of '…\n'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this comment to the code :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also unnecessary ()
around max_length
.
docs/installation.rst
Outdated
|
||
.. attribute:: SECURITY_LOG_STRING_OUTPUT_TRUNCATE_OFFSET | ||
|
||
Because too often string truncation can cause high CPU load text is truncated is truncated by more characters. Setting define this value which default value is ``1000``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because too often string truncation can cause high CPU load text is truncated is truncated by more characters. Setting define this value which default value is ``1000``. | |
Because too frequent string truncation can cause high CPU load, log string is truncated by more characters. This setting defines this value which is by default ``1000``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar description is also down below, in the docstring.
security/utils.py
Outdated
@@ -32,17 +32,31 @@ def is_atty_string(s): | |||
return bool(re.search(r'^' + re.escape('\x1b[') + r'\d+m$', s)) | |||
|
|||
|
|||
def truncate_newline_from_left(value, max_length): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather name it truncate_lines_from_left
.
security/utils.py
Outdated
if len(value) <= max_length: | ||
return value | ||
|
||
truncated_value = value[len(value) + 2 - (max_length):] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this comment to the code :-)
security/utils.py
Outdated
truncated_value_split_by_newline[0] | ||
if len(truncated_value_split_by_newline) == 1 | ||
else truncated_value_split_by_newline[1] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note. I can imagine a situation, when command prints a looooong line with for example IDs processed, and then prints "DONE". Then the log will contain just "DONE".
Processed IDs: 1,2,3,4,5,6,7,8,9.................
DONE.
This can be a surprising behavior. Maybe it should be mentioned in the documentation.
def test_log_string_io_should_be_truncated_according_to_settings(self): | ||
log_string_io = LogStringIO(write_time=False) | ||
for _ in range(20): | ||
log_string_io.write((4*'a') + '\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add spaces between operator and operands. Also on the line below.
assert_equal(log_string_io.getvalue(), 20 * (4*'a' + '\n')) | ||
assert_equal(len(log_string_io.getvalue()), 100) | ||
log_string_io.write('b') | ||
assert_equal(log_string_io.getvalue(), '…\n' + 17 * (4 * 'a' + '\n') + 'b') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 17
instead of 19
? The b
causes exceeding the limit, so one line is stripped off and replaced with …\n
. (I know tests are passing, maybe I am a little tired today and not getting it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two reasons, offset 10 characters which will do 18 but, b character is computed to the limit to. This is the reason why 17
2bccdad
to
09500b0
Compare
09500b0
to
8ae9f93
Compare
No description provided.