-
Notifications
You must be signed in to change notification settings - Fork 572
backend: Allow configuring log level via environment variable #4458
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
base: main
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: aadhil2k4 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
|
Welcome @aadhil2k4! |
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.
Pull request overview
This PR adds support for configuring the Headlamp backend log level via the HEADLAMP_LOG_LEVEL environment variable, addressing issue #4139. The implementation uses zerolog's SetGlobalLevel method to configure logging at application startup.
Changes:
- Added a new
Init()function in the logger package to configure log levels from theHEADLAMP_LOG_LEVELenvironment variable - Called
logger.Init()at the start of the main function in server.go to initialize logging before any other operations - Implemented error handling for invalid log level values with a fallback to info level
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| backend/pkg/logger/logger.go | Added Init function to parse HEADLAMP_LOG_LEVEL environment variable and set global zerolog log level with error handling |
| backend/cmd/server.go | Added logger.Init() call at the beginning of main() to initialize logging configuration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@illume I think this PR can be merged. Can you please check it once? |
illume
left a comment
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.
Looking good.
I think this should be a backend configuration flag. This then is automatically available as an environment variable as well. Additionally there is some help available for users.
It should be documented with the other backend flags somewhere in the documentation. For example the in-cluster documentation, and backend developer documentation (How do I turn on debug or verbose logging? How do I reduce logging to only info?)
@illume I have a doubt, Headlamp doesnt define a Debug log level. Should I add a Debug level to the logger too ? |
|
@aadhil2k4 zlog has a default debug log level of info. Headlamp just uses the default. |
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.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 11 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@aadhil2k4 thanks for that. Looking good. I'll test it a bit later. Please remember to squash/rebase and remove the Signed-off-by from commit messages? |
Sure, I'll do it. 👍 |
…date tests and development docs
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.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| Backend log verbosity can be controlled using either a flag or an environment variable. | ||
| - `--log-level` | ||
| - `HEADLAMP_CONFIG_LOG_LEVEL` |
Copilot
AI
Feb 2, 2026
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.
Corrected spelling of 'HEADLAMP_CONFIG_LOG_LEVEL' to 'HEADLAMP_LOG_LEVEL'.
| - `HEADLAMP_CONFIG_LOG_LEVEL` | |
| - `HEADLAMP_LOG_LEVEL` |
| Headlamp’s backend supports configurable log levels to control verbosity. | ||
|
|
||
| Log level can be configured using either a flag or an environment variable: | ||
| - the log level: `--log-level` or env var `HEADLAMP_CONFIG_LOG_LEVEL` |
Copilot
AI
Feb 2, 2026
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.
Corrected spelling of 'HEADLAMP_CONFIG_LOG_LEVEL' to 'HEADLAMP_LOG_LEVEL'.
| - the log level: `--log-level` or env var `HEADLAMP_CONFIG_LOG_LEVEL` | |
| - the log level: `--log-level` or env var `HEADLAMP_LOG_LEVEL` |
| var logFunc LogFunc = log | ||
|
|
||
| // Init configures the global zerolog log level from environment variables. | ||
| // The HEADLAMP_CONFIG_LOG_LEVEL environment variable controls the global log level. |
Copilot
AI
Feb 2, 2026
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.
Corrected spelling of 'HEADLAMP_CONFIG_LOG_LEVEL' to 'HEADLAMP_LOG_LEVEL'.
| Str("value", logLevel). | ||
| Msg("Invalid HEADLAMP_CONFIG_LOG_LEVEL, defaulting to info") |
Copilot
AI
Feb 2, 2026
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.
Corrected spelling of 'HEADLAMP_CONFIG_LOG_LEVEL' to 'HEADLAMP_LOG_LEVEL'.
| Str("level", level.String()). | ||
| Msg("Log level set from HEADLAMP_CONFIG_LOG_LEVEL") |
Copilot
AI
Feb 2, 2026
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.
Corrected spelling of 'HEADLAMP_CONFIG_LOG_LEVEL' to 'HEADLAMP_LOG_LEVEL'.
|
@illume HEADLAMP_CONFIG_ is the naming convention for environment variables. Those are the only suggestions from Copilot. Shall I mark them as resolved? |
Summary
This PR adds the ability to configure the Headlamp backend log level via the
HEADLAMP_CONFIG_LOG_LEVELenvironment variable.Related Issue
Fixes #4139
Changes
HEADLAMP_CONFIG_LOG_LEVELenvironment variableinfoSteps to Test
cd backendIf it doesnt work, build the backend again using
npm run backend:buildand follow the above steps.Screenshots (if applicable)
Notes for the Reviewer
None