Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@happenslol
Copy link
Contributor

Closes #366.

This allows setting the log level through PC_LOG_LEVEL. I chose to abort if an invalid log level is passed, since I wouldn't expect this to occur unless the user specifically set the env var and would want to be notified if it's invalid. We could alternatively emit an error log here if you want.

Additionally, the warning log when no global config is found is changed to a debug log instead.

Copy link
Owner

@F1bonacc1 F1bonacc1 left a comment

Choose a reason for hiding this comment

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

Thank you @happenslol,
The code looks good and indeed addresses the issue.
But there are 2 potential issues:

  1. In case there is project level log level, the PC_LOG_LEVEL variable should override that.
  2. I think this won't happen, because the location in which you parse the env variable is not in the right place. I think it should be here:
    func validateLogLevel(p *types.Project) error {
    if p.LogLevel != "" {
    lvl, err := zerolog.ParseLevel(p.LogLevel)
    if err != nil {
    if p.IsStrict {
    return fmt.Errorf("unknown log level %s", p.LogLevel)
    }
    log.Warn().Msgf("Unknown log level %s defaulting to %s",
    p.LogLevel, zerolog.GlobalLevel().String())
    } else {
    zerolog.SetGlobalLevel(lvl)
    }
    }
    return nil
    }

This will also allow you to reuse some of the things that already exit there.

@sonarqubecloud
Copy link

@happenslol
Copy link
Contributor Author

That makes it a lot easier! Is this better, or should I put the code inside a mutator function that is then applied?

@F1bonacc1 F1bonacc1 merged commit 5dc8912 into F1bonacc1:main Jul 22, 2025
5 checks passed
@happenslol happenslol deleted the improve-logging branch August 5, 2025 22:16
@happenslol
Copy link
Contributor Author

@F1bonacc1 Any chance you could cut a release soon, including this?

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.

Config path warning on every startup

2 participants