Skip to content

Commit 45eeb3f

Browse files
authored
chore: allow log level to be set via CSB_LOG_LEVEL (#1324)
Exposes and documents the CSB_LOG_LEVEL environment variable to allow the Lager log level to be set.
1 parent 21e99ef commit 45eeb3f

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Values for debugging:
9494
| Environment Variable | Config File Value | Type | Description |
9595
|----------------------------------------|---------------------------|------|-------------------------------------------------------------------------------------------------|
9696
| <tt>CSB_DEBUG_LEAVE_WORKSPACE_DIR</tt> | debug.leave_workspace_dir | bool | Disables the cleanup of workspace directories, so you can inspect the files and run tf commands |
97+
| <tt>CSB_LOG_LEVEL</tt> | (none) | string | Sets the logging level to the specified value, which can be one of `debug`, `info`, `error`, `fatal` |
98+
| <tt>GSB_DEBUG</tt> | (none) | bool | If set to any value, the log level is set to `debug`. Overrides `CSB_LOG_LEVEL` |
9799

98100
## Feature flags Configuration
99101

internal/local/environment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func passThroughEnvs() []string {
13-
result := append(manifestAllowedEnvs(), "TF_LOG", "TF_LOG_CORE", "TF_LOG_PROVIDER", "TF_LOG_PATH")
13+
result := append(manifestAllowedEnvs(), "TF_LOG", "TF_LOG_CORE", "TF_LOG_PROVIDER", "TF_LOG_PATH", "CSB_LOG_LEVEL")
1414
result = append(result, featureflags.AllFeatureFlagEnvVars...)
1515
return result
1616
}

utils/utils.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,19 @@ func SingleLineErrorFormatter(es []error) string {
138138
// writing settings.
139139
func NewLogger(name string) lager.Logger {
140140
logger := lager.NewLogger(name)
141+
logLevel := lager.INFO // default
142+
143+
// Can use environment variable CSB_LOG_LEVEL to set the level.
144+
// If the value is invalid, we ignore it.
145+
if level, ok := os.LookupEnv("CSB_LOG_LEVEL"); ok {
146+
parsedLevel, err := lager.LogLevelFromString(level)
147+
if err == nil {
148+
logLevel = parsedLevel
149+
}
150+
}
141151

142-
logLevel := lager.INFO
152+
// The GSB_DEBUG environment variable is the long-standing way
153+
// to enable debug logging, and it overrides CSB_LOG_LEVEL
143154
if _, debug := os.LookupEnv("GSB_DEBUG"); debug {
144155
logLevel = lager.DEBUG
145156
}

0 commit comments

Comments
 (0)