Skip to content

Conversation

@aadhil2k4
Copy link

@aadhil2k4 aadhil2k4 commented Jan 26, 2026

Summary

This PR adds the ability to configure the Headlamp backend log level via the HEADLAMP_CONFIG_LOG_LEVEL environment variable.

Related Issue

Fixes #4139

Changes

  • Added support for configuring the backend log level via the HEADLAMP_CONFIG_LOG_LEVEL environment variable
  • Initialized the global zerolog log level during application startup
  • Ensured invalid or missing log level values safely default to info

Steps to Test

  1. Go backend folder:
    cd backend
  2. Run the following command:
    npm run backend:start -- --log-level debug
    

If it doesnt work, build the backend again using npm run backend:build and follow the above steps.

Screenshots (if applicable)

  1. Debug log level
SCR-20260202-tydl
  1. Warn log level
SCR-20260202-tyhm

Notes for the Reviewer

None

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: aadhil2k4
Once this PR has been reviewed and has the lgtm label, please assign illume for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 26, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: aadhil2k4 / name: Aadhil Ahamed (b03b74c)

@k8s-ci-robot k8s-ci-robot requested a review from sniok January 26, 2026 19:36
@k8s-ci-robot
Copy link
Contributor

Welcome @aadhil2k4!

It looks like this is your first PR to kubernetes-sigs/headlamp 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/headlamp has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot requested a review from yolossn January 26, 2026 19:36
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 26, 2026
@aadhil2k4
Copy link
Author

@yolossn @sniok If this approach is acceptable, I can update the documentation to include the Log Level details. Please review the PR and let me know if any changes/additions are required.

Copy link
Contributor

Copilot AI left a 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 the HEADLAMP_LOG_LEVEL environment 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.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 29, 2026
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 29, 2026
@aadhil2k4 aadhil2k4 requested a review from Copilot January 29, 2026 21:20
Copy link
Contributor

Copilot AI left a 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.

@aadhil2k4
Copy link
Author

@illume I think this PR can be merged. Can you please check it once?

Copy link
Contributor

@illume illume left a 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?)

@aadhil2k4
Copy link
Author

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 ?

@illume
Copy link
Contributor

illume commented Feb 1, 2026

@aadhil2k4 zlog has a default debug log level of info. Headlamp just uses the default.

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 2, 2026
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 2, 2026
@aadhil2k4 aadhil2k4 requested a review from Copilot February 2, 2026 17:34
Copy link
Contributor

Copilot AI left a 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.

@illume
Copy link
Contributor

illume commented Feb 2, 2026

@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?

@aadhil2k4
Copy link
Author

aadhil2k4 commented Feb 2, 2026

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

@illume illume requested a review from Copilot February 2, 2026 20:56
@illume illume added this to the v0.40.0 milestone Feb 2, 2026
Copy link
Contributor

Copilot AI left a 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`
Copy link

Copilot AI Feb 2, 2026

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

Suggested change
- `HEADLAMP_CONFIG_LOG_LEVEL`
- `HEADLAMP_LOG_LEVEL`

Copilot uses AI. Check for mistakes.
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`
Copy link

Copilot AI Feb 2, 2026

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

Suggested change
- the log level: `--log-level` or env var `HEADLAMP_CONFIG_LOG_LEVEL`
- the log level: `--log-level` or env var `HEADLAMP_LOG_LEVEL`

Copilot uses AI. Check for mistakes.
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.
Copy link

Copilot AI Feb 2, 2026

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

Copilot uses AI. Check for mistakes.
Comment on lines +60 to +61
Str("value", logLevel).
Msg("Invalid HEADLAMP_CONFIG_LOG_LEVEL, defaulting to info")
Copy link

Copilot AI Feb 2, 2026

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

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +71
Str("level", level.String()).
Msg("Log level set from HEADLAMP_CONFIG_LOG_LEVEL")
Copy link

Copilot AI Feb 2, 2026

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

Copilot uses AI. Check for mistakes.
@aadhil2k4
Copy link
Author

@illume HEADLAMP_CONFIG_ is the naming convention for environment variables. Those are the only suggestions from Copilot. Shall I mark them as resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change LogLevel of Headlamp

3 participants