-
Notifications
You must be signed in to change notification settings - Fork 40
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
[#396] Read and set LogLevel from environment variable #474
base: main
Are you sure you want to change the base?
[#396] Read and set LogLevel from environment variable #474
Conversation
Moreover, please follow the convention here:
|
@zmostafa hey hey ... you are back. I am happy to see your PR plopping up here. |
@elfenpiff you have to thank Jeff for the motivation, and thanks for the nice words as expected from you. You guys are the best ❤️ |
d8372ae
to
56705a0
Compare
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.
@zmostafa great to have you back :)
I guess you need to sign the ECA. It can be done as individual contributor if you do the contributions in your spare time.
iceoryx2-bb/log/src/lib.rs
Outdated
pub static ENV_LOG_LEVEL: Lazy<LogLevel> = Lazy::new(|| { | ||
let log_level_str = env::var("IOX2_LOG_LEVEL").unwrap_or_else(|_| "Info".to_string()); | ||
LogLevel::from_str(&log_level_str) // Default to Info | ||
}); |
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 great. I had something else in mind when I created the issue but this idea is better :)
My only concern is the allocation with String
, which is a hurdle for ASIL-D. But that can be solved with a feature flag later on.
I would also suggest to use .map(LogLevel::from_str).unwrap_or(DEFAULT_LOG_LEVEL)
. This is one less allocation.
The lazy initialization is problematic in this case. Let's assume the following scenario
- set env variable to trace
- start process A
- set env variable to fatal
- start process B
- process A reads the env variable and sets it to fatal instead of trace
Since the initialization is dependent on an external state, the evaluation should be done when the application starts.
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.
- Can you explain more about string allocation? how do you track/bench them?
- about the scenario you mentioned, is not it what should be in the first place? since we might run different instance of application from or within the same shell/env? so each application will utilize its 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.
- There would be heaptrack as a nice gui to track all heap allocation. But in this case I just know that
String
will allocate on the heap from its documentation. - Each application will utilize its own logger instance but if the reading of the env variable is delayed, application A might read the value which was set after it was started and meant to be the value for application 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.
@zmostafa can you please revert the lazy initialization for the 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.
@elBoberido I reverted back the DEFAULT_LOGGER lazy initialization
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.
Can you do the same for ENV_LOG_LEVEL
e88f644
to
11c89b3
Compare
41fbf0d
to
133a906
Compare
fd7db00
to
e2e818c
Compare
14d1d19
to
890e941
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #474 +/- ##
==========================================
+ Coverage 79.22% 79.64% +0.42%
==========================================
Files 200 200
Lines 23765 23779 +14
==========================================
+ Hits 18828 18939 +111
+ Misses 4937 4840 -97
|
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.
@zmostafa sorry for the slow response. I was quite busy the last days, but I try to improve on my response time :)
Signed-off-by: Ziad Mostafa <[email protected]>
Signed-off-by: Ziad Mostafa <[email protected]>
Signed-off-by: Ziad Mostafa <[email protected]>
dbf9096
to
84e592c
Compare
@@ -58,24 +58,22 @@ insufficient, a new publisher with a larger `max_slice_len` can be created. | |||
|
|||
<!-- markdownlint-disable --> | |||
|
|||
> [!IMPORTANT] | |||
> Be aware that the history of the old publisher is lost when it is | |||
> [!IMPORTANT] Be aware that the history of the old publisher is lost when it is |
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.
Oh no, does the script have some autocorrection?
This breaks the github alerts syntax. > [!IMPORTANT]
must be on a separate line than the content
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.
@zmostafa can you please revert those changes. It breaks the alert syntax. Please also have a look at the other open point.
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.
@elBoberido hmmm, I think i did, are you sure you are looking at the latest commit?
I will check the other point about reverting the lazy init, did not see that
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.
@zmostafa I hope to look at the latest commit 😅
I did a Ctrl+F5, which should reload everything and dismiss caches but I still see > [!IMPORTANT]
on the same line as Be aware that ...
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.
Note I believe this happens because the auto-corrector does not recognise GitHub-style admonitions, so you need to manually ensure these are on their own line otherwise the auto corrector will try and do line length correction with it on the same line.
Not ideal, I know, but the idea is for the corrector to fix around 90% of the issues which should save more time than manually fixing these small edge cases (e.g. manually fixing all line lengths).
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.
Can we skip line breaks in the auto-corrector? It's just a styling issue, not a rendering issue and it seems to break the github admonitions.
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 believe this is the line length corrector causing this. If disabled, then users would need to ensure line length limits were maintained, either manually or with an IDE. I deduced that this would be a larger annoyance for contributors than fixing these more limited edge cases.
Of course, we could check if the auto corrector could be updated to recognise the GitHub admonitions.
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.
Well, I would argue that one is not only an annoyance but breaks the rendering of the readme if the reviewer does not pay attention and the other one is a choice by ourselves and does not break the rendering if the line is too long. I would rather deactivate the line length detection than having to keep in mind to check for broken admonitions in the PR.
Signed-off-by: Ziad Mostafa <[email protected]>
Signed-off-by: Ziad Mostafa <[email protected]>
Notes for Reviewer
Adds functionality to set the log level from the environment.
I went for @elBoberido proposal solution, where I read an environment variable called
IOX2_LOG_LEVEL
and set the LogLevel, with its value at runtime.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
Closes #396