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

[#396] Read and set LogLevel from environment variable #474

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

zmostafa
Copy link

@zmostafa zmostafa commented Oct 16, 2024

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

  1. Add sensible notes for the reviewer
  2. PR title is short, expressive and meaningful
  3. Relevant issues are linked in the References section
  4. Every source code file has a copyright header with SPDX-License-Identifier: Apache-2.0 OR MIT
  5. Branch follows the naming format (iox2-123-introduce-posix-ipc-example)
  6. Commits messages are according to this guideline
  7. Tests follow the best practice for testing
  8. Changelog updated in the unreleased section including API breaking changes
  9. Assign PR to reviewer
  10. All checks have passed (except task-list-completed)

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Unit tests have been written for new behavior
  • Public API is documented
  • PR title describes the changes

Post-review Checklist for the PR Author

  1. All open points are addressed and tracked via issues

References

Closes #396

@xieyuschen
Copy link
Contributor

xieyuschen commented Oct 16, 2024

Moreover, please follow the convention here:

  • title: [#396]: Read and set LogLevel from environment variable

@elfenpiff
Copy link
Contributor

@zmostafa hey hey ... you are back. I am happy to see your PR plopping up here.

@zmostafa
Copy link
Author

@elfenpiff you have to thank Jeff for the motivation, and thanks for the nice words as expected from you.

You guys are the best ❤️

@zmostafa zmostafa changed the title Read and set LogLevel from environment variable [#396]: Read and set LogLevel from environment variable Oct 16, 2024
@zmostafa zmostafa force-pushed the iox2-396-configure-debug-level-from-env branch from d8372ae to 56705a0 Compare October 16, 2024 19:12
Copy link
Member

@elBoberido elBoberido left a 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.

Comment on lines 168 to 170
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
});
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

  1. Can you explain more about string allocation? how do you track/bench them?
  2. 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?

Copy link
Member

Choose a reason for hiding this comment

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

  1. 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.
  2. 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.

Copy link
Member

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

Copy link
Author

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

Copy link
Member

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

iceoryx2-bb/log/src/lib.rs Outdated Show resolved Hide resolved
iceoryx2-bb/log/src/lib.rs Outdated Show resolved Hide resolved
@zmostafa zmostafa force-pushed the iox2-396-configure-debug-level-from-env branch from e88f644 to 11c89b3 Compare October 17, 2024 10:48
@orecham orecham changed the title [#396]: Read and set LogLevel from environment variable [#396] Read and set LogLevel from environment variable Oct 17, 2024
@zmostafa zmostafa force-pushed the iox2-396-configure-debug-level-from-env branch 2 times, most recently from 41fbf0d to 133a906 Compare October 22, 2024 01:03
@zmostafa zmostafa force-pushed the iox2-396-configure-debug-level-from-env branch 2 times, most recently from fd7db00 to e2e818c Compare October 30, 2024 12:46
@zmostafa zmostafa force-pushed the iox2-396-configure-debug-level-from-env branch from 14d1d19 to 890e941 Compare November 7, 2024 09:35
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 64.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 79.64%. Comparing base (810fb87) to head (e2b323c).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
iceoryx2-bb/log/src/lib.rs 64.00% 9 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
iceoryx2-bb/log/src/lib.rs 73.77% <64.00%> (-3.16%) ⬇️

... and 21 files with indirect coverage changes

Copy link
Member

@elBoberido elBoberido left a 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 :)

FAQ.md Outdated Show resolved Hide resolved
FAQ.md Outdated Show resolved Hide resolved
@zmostafa zmostafa force-pushed the iox2-396-configure-debug-level-from-env branch from dbf9096 to 84e592c Compare November 8, 2024 15:16
@@ -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
Copy link
Member

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

Copy link
Member

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.

Copy link
Author

@zmostafa zmostafa Nov 12, 2024

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

Copy link
Member

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 ...

Copy link
Contributor

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).

Copy link
Member

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.

Copy link
Contributor

@orecham orecham Nov 13, 2024

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.

Copy link
Member

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.

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.

Add -l / --log-level option to all examples
5 participants