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

log: improve timestamps on stderr log output #321

Merged
merged 2 commits into from
Jun 19, 2023

Conversation

mkemel
Copy link
Member

@mkemel mkemel commented May 30, 2023

This adds date and milliseconds to the timestamp output to stderr-full, and also adds timestamp to stderr log output

[mkemel@lptp systemd]$ sudo hirte-agent -c ~/hirte-conf/agent.conf
2023-06-12 08:56:46,331+0300 DEBUG	: Final configuration used
2023-06-12 08:56:46,332+0300 DEBUG	: Connected to system bus
2023-06-12 08:56:46,332+0300 DEBUG	: Connected to systemd bus
2023-06-12 08:56:46,336+0300 INFO	: Connecting to manager on tcp:host=127.0.0.1,port=842
2023-06-12 08:56:46,337+0300 INFO	: Connected to manager as 'laptop'

@mkemel mkemel force-pushed the metrics branch 4 times, most recently from 1f2da31 to 36d7c8e Compare May 30, 2023 12:55
Copy link
Member

@engelmi engelmi left a comment

Choose a reason for hiding this comment

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

I am not sure if logging the date provides much value since stderr-full is - usually - used for local development etc. and with journal logging we get the date anyway. The milliseconds might be pretty useful for developing, though.

@mkemel mkemel force-pushed the metrics branch 2 times, most recently from ee6f146 to e3b58a5 Compare May 31, 2023 13:35
@rhatdan
Copy link
Contributor

rhatdan commented Jun 15, 2023

@mkemel What is going on with this PR?

@mkemel
Copy link
Member Author

mkemel commented Jun 18, 2023

So now it's a full timestamp including timezone
2023-06-12 08:56:46,331+0300 DEBUG : Final configuration used
I thought how to test that, but since the expected output of the function is dependent on the timezone setting of the machine it's running on, I couldn't think of a way to test that without assembling the expected output exactly the way it is done in the tested function, which doesn't test much.
Any ideas? Or just skip unit test for that one?

@engelmi
Copy link
Member

engelmi commented Jun 18, 2023

So now it's a full timestamp including timezone 2023-06-12 08:56:46,331+0300 DEBUG : Final configuration used I thought how to test that, but since the expected output of the function is dependent on the timezone setting of the machine it's running on, I couldn't think of a way to test that without assembling the expected output exactly the way it is done in the tested function, which doesn't test much. Any ideas? Or just skip unit test for that one?

Basically make the time format function testable by passing the time struct to it like Martin described here:
#321 (comment)
This way also does only one thing (formatting), adhering to srp, and not two.

@mkemel
Copy link
Member Author

mkemel commented Jun 18, 2023

@engelmi That's what I did, but time struct does not have timezone info.
In any case, I looked at it again now, and I see that there's a function that returns Greenwich time struct for a given time struct so that might help

@mkemel
Copy link
Member Author

mkemel commented Jun 18, 2023

We are not talking about struct tm, which does include timezone info, but has only seconds resolution. We use struct timespec.
Now I see that I can alter the timestamp function to have a flag to show Greenwich time. This is not very useful except for testing purposes, but it won't hurt

@mkemel
Copy link
Member Author

mkemel commented Jun 18, 2023

Okay, all done including tests

@mkemel
Copy link
Member Author

mkemel commented Jun 18, 2023

Integration test failure is unrelated

mkemel added 2 commits June 19, 2023 09:40
This adds date and milliseconds to the timestamp output to
stderr-full, and also adds timestamp to stderr log output

Signed-off-by: Mark Kemel <[email protected]>
Copy link
Member

@engelmi engelmi left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks for adding unit tests!

@engelmi engelmi merged commit 9afb87a into eclipse-bluechi:main Jun 19, 2023
@pypingou
Copy link
Member

pypingou commented Jun 19, 2023 via email

@mkemel mkemel deleted the metrics branch January 10, 2024 13:47
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.

5 participants