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

timestamp logs misleading #9

Closed
BobIV opened this issue May 14, 2015 · 7 comments
Closed

timestamp logs misleading #9

BobIV opened this issue May 14, 2015 · 7 comments

Comments

@BobIV
Copy link

BobIV commented May 14, 2015

When the log details are generated in g2logmessage.cpp, it creates the following output:

2015/03/12 14:21:43.27000 INFO [processframework.cpp L: 138] "IPAddress read: 127.0.0.1"

Reading the timestamp and a high level view of the source code, I interpret the timestamp as:

year/month/day hour:min:sec.microsecond ....

From a single log entry it is not clear that the microsecond counter starts at the time g3log was initialized and counts up from there.

When using these log statements, the microsecond portion of the timestamp should be extracted from the rest of the timestamp for use in any sort of measurements.

I think it is best to separate these two components of the time stamp to highlight that they should not be interpreted as a fraction of the seconds from the system time seconds.

@KjellKod
Copy link
Owner

Unfortunately this is a c-library issue.
The finest granularity you get on std::time_t is seconds. To be able to differentiate between the entries that end up in the same second timeframe it is handy to have the microseconds counter.

I'm closing this since it's a c-library limitation and not a g3log bug.

Feel free to do a pull request in case you come up with a great way of solving this.

@BobIV
Copy link
Author

BobIV commented May 14, 2015

It's not the granularity that is the issue. It's the concatenation of the two numbers that creates inaccurate numbers. 

-------- Original message --------
From: Kjell Hedstrom notifications@github.com
Date:05/14/2015 3:56 PM (GMT-05:00)
To: KjellKod/g3log g3log@noreply.github.com
Cc: BobIV bobflynn4@comcast.net
Subject: Re: [g3log] timestamp logs misleading (#9)
Unfortunately this is a c-library issue. The finest granularity you get on std::time_t is seconds. To be able to differentiate between the entries that end up in the same second timeframe it is handy to have the microseconds counter.

I'm closing this since it's a c-library limitation and not a g3log bug.

Feel free to do a pull request in case you come up with a great way of solving this.


Reply to this email directly or view it on GitHub.

@KjellKod
Copy link
Owner

It can be easily changed to whatever formatting you like.

g3log was made to support custom sinks. What formatting and how to output the logs can be done from a custom sink. Adding a custom sink is very easy. Please see the unit tests as well as the README for this repo: https://github.com/KjellKod/g3log

If you want to achieve custom formatting using your own sink, then you should choose to have the log receiving function receive a g2::LogMessageMover message instead of a std::string. This way you can do your own formatting on the log output.

Please see:

  • src/g2time.hpp/cpp
    std::string localtime_formatted(const std::time_t& time_snapshot, const std::string& time_format) ;

For how to use your own custom time formatting, please see examples of this, here

  • src/g2filesink.hpp/cpp ::changeLogFile()
  • src/g2filesinkhelper.hpp/cpp (more examples here)

@BobIV
Copy link
Author

BobIV commented May 14, 2015

Your code is very well done and straight forward to customize, you did a great job.  

This particular topic was a slight problem that had a significant impact to some work I was  doing. I felt the need to share the issue, but I think I am having trouble making my point clear. 

I would like to continue to try to explain this issue, but will refrain from continuing this thread unless you are interested. 

Your utilities are quite useful, and your efforts are appreciated. 

Thanks 
Bob 

-------- Original message --------
From: Kjell Hedstrom notifications@github.com
Date:05/14/2015 4:54 PM (GMT-05:00)
To: KjellKod/g3log g3log@noreply.github.com
Cc: BobIV bobflynn4@comcast.net
Subject: Re: [g3log] timestamp logs misleading (#9)
It can be easily changed to whatever formatting you like.

g3log was made to support custom sinks. What formatting and how to output the logs can be done from a custom sink. Adding a custom sink is very easy. Please see the unit tests as well as the README for this repo: https://github.com/KjellKod/g3log

If you want to achieve custom formatting using your own sink, then you should choose to have the log receiving function receive a g2::LogMessageMover message instead of a std::string. This way you can do your own formatting on the log output.

For how to use your own custom time formatting, please see
src/g2time.hpp/cpp
std::string localtime_formatted(const std::time_t& time_snapshot, const std::string& time_format) ;
src/g2filesink.hpp/cpp ::changeLogFile()

src/g2filesinkhelper.hpp/cpp (more examples here)


Reply to this email directly or view it on GitHub.

@KjellKod
Copy link
Owner

Feedback is always welcome

Feel free if you want to contact me off line. Hedstrom at kjellkod dot cc

@KjellKod
Copy link
Owner

Fixed in #16

@KjellKod
Copy link
Owner

@BobIV true timestamp and not just a time counter is addressed in this pull request: #104

It gives the user/sink the option of using millisecond, microsecond or nanosecond as a true timestamp. The default will be microseconds.

So far it is implemented for OSX and Linux. The pull request will only be merged when it is fixed for Windows also. For OSX and Windows the granularity is so far not as great as nanosecond.

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

No branches or pull requests

2 participants