-
Notifications
You must be signed in to change notification settings - Fork 36
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
[#464] file logger #465
[#464] file logger #465
Conversation
37d68b8
to
82a167a
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #465 +/- ##
==========================================
- Coverage 79.14% 78.92% -0.22%
==========================================
Files 196 197 +1
Lines 23538 23637 +99
==========================================
+ Hits 18629 18656 +27
- Misses 4909 4981 +72
|
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.
Looks fine for me, will let @elBoberido comment on the Rust. Ping me if needed.
|
||
/// A logger that logs all messages into a file. It implements an active object pattern. A | ||
/// background thread waits on a queue of log messages and whenever a new message is added. | ||
pub struct Logger { |
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.
Regards on the log level, currently i saw we use a static log level to do so. But if we have supported the file logger, I believe it's reasonable to spawn multiple loggers which writes to different files(such as errors.log and info.log, debug.log) in the future.
Probably it's nice to let the logger holds its own log level, it allows us spawn many file loggers with different level.
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.
But this would still be possible with this approach. You could create a custom MultiFileLogger
which uses a log file for every log level.
iceoryx2-bb/log/src/logger/file.rs
Outdated
timestamp: SystemTime::now() | ||
.duration_since(SystemTime::UNIX_EPOCH) | ||
.expect("Acquire current system time."), | ||
elapsed_time: self.start_time.elapsed(), |
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 curious, why does the creation time of a logger matters for each piece of log here. Looks like it's not a useful information for each piece of log.
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.
timestamp
- useful when debugging many processes that log in many log files to have some kind of total order across these log files. But the UNIX time stamp does not really tell you if the thing occurred during the start of a program or after running for hourselapsed_time
- Maybe a better name is needed. Useful when you have a bug that always occurs 10 seconds after starting the process (we already had some of them). Then you start investigating the logs that were created around 10 seconds after process startup.
So the elapsed_time
relates somehow to the process startup time since the logger is the first thing that is created in a process.
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.
Useful when you have a bug that always occurs 10 seconds after starting the process (we already had some of them).
I see, it may help you to figure out the bugs before. But does the gap(500ms or less?) between starting process and logger creation matters for a fragile and weird bug?
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.
We are talking here about single-digit micro-seconds so I think it is fine. This will never be perfect but we try to provide as much insights as possible for the next developer that has to debug something.
.as_bytes(), | ||
) | ||
.expect("Write log message into log file."), | ||
}; | ||
file.sync_all().expect("Sync log file with disc."); |
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.
will sync_all
cost a lot for every piece of messages? I have searched the forum mentioned it in this post. Hdyt?
B) Asking the OS to dump its in-memory ... . it can be a slow and expensive operation.
This operation is not required for data to become visible to other applications.
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 guess the idea was to have the logs available when a crash occurs. Maybe this can be done via a crash handler. On the other side, AFAIK there are no logs in the hot path, so it should also not affect performance.
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.
AFAIK there are no logs in the hot path
Every log
call will send a message and the write_buffer_to_file
will call sync_all
, it's in the hot path.
It's a bit different from previously the continuous log
call will make the queue not empty so sync_all
won't be triggered. PCMIIW
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.
This is why all of this is handled in a background thread. The hot path just uses the channel to move the log message out of the hot thread into the log thread.
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 think the worst case scenario is, when a crash happens and the logger didn't sync the file and therefore the final log messages are not written.
However, I also want to highlight that this does not need to be the final implementation. If we realize this becomes a bottleneck we can put on our thinking caps and try harder.
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.
LGTM, thanks for your clarify.
Notes for Reviewer
Implements a simple file logger that does not use any additional crates and where we can add a simple C/C++ binding for it to be able to exchange loggers from different languages.
Pre-Review Checklist for the PR Author
SPDX-License-Identifier: Apache-2.0 OR MIT
iox2-123-introduce-posix-ipc-example
)[#123] Add posix ipc example
)task-list-completed
)Checklist for the PR Reviewer
Post-review Checklist for the PR Author
References
Relates to #464