Skip to content

#490: In CommandLogHandler suffixed newline, flushed logfile and added timestamp #499

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

Merged
merged 6 commits into from
Jul 16, 2025

Conversation

sgn4sangar
Copy link
Contributor

Fixes #490

)


def test_new_line(tmp_path):
Copy link
Contributor

Choose a reason for hiding this comment

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

we probably need another test, that checks if the timestamp gets prepended

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

log_handler.handle_log_line("log line 1")
log_handler.handle_log_line("log line 2")
with open(log_file_path) as log_file:
line_count = sum(1 for line in log_file)
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting construction, I like it; this actually would stream the file , which is good for large files. Maybe a bit overkill, but perfectly ok.

Comment on lines 21 to 24
timestamp = cur_time.strftime("%H.%M.%S")
msecs = str(int(cur_time.microsecond / 1000))
usecs = str(int(cur_time.microsecond % 1000))
return timestamp + "." + msecs + "." + usecs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
timestamp = cur_time.strftime("%H.%M.%S")
msecs = str(int(cur_time.microsecond / 1000))
usecs = str(int(cur_time.microsecond % 1000))
return timestamp + "." + msecs + "." + usecs
timestamp = cur_time.strftime("%H.%M.%S.%f")
return timestamp

I don't think we need to split the microseconds more. https://docs.python.org/3.10/library/datetime.html#strftime-strptime-behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the static method timestamp_for_logging() and used the default 6 digits microseconds

@sgn4sangar sgn4sangar changed the title #490: Improved CommandLogHandler on top of 4.2.0 #490: In CommandLogHandler suffixed newline, flushed logfile and added timestamp Jul 15, 2025
log_handler.handle_log_line("log line 1")
with open(log_file_path) as log_file:
first_line = log_file.readline()
assert re.match(pattern, first_line)
Copy link
Collaborator

@tomuben tomuben Jul 15, 2025

Choose a reason for hiding this comment

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

Suggested change
assert re.match(pattern, first_line)
assert re.match(pattern, first_line), f"{first_line} does not match {pattern}"

Copy link
Contributor

Choose a reason for hiding this comment

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

do we have the regex_matcher already in this project?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, we have,

, pls use that one then

@sgn4sangar sgn4sangar deployed to manual-approval July 15, 2025 13:42 — with GitHub Actions Active
Copy link

@sgn4sangar sgn4sangar merged commit 7b7a4c1 into main Jul 16, 2025
137 checks passed
@sgn4sangar sgn4sangar deleted the refactoring/490_improve_command_log_handler_4_2_0 branch July 16, 2025 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve CommandLogHandler
3 participants