-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add debug logging levels #664
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
052f157
Move config init to before logging init
idlewis b0a45a1
Log 'Reconciled' messages at debug1 level
idlewis b5cbdbc
Allow log level to be configured through config
idlewis 3ac9c8c
Add debugmax to log everything
idlewis cdc0287
Review comments
idlewis 286bcca
Only log stack traces in debug logs
idlewis 6100cd5
Move logging functions into common code
idlewis 61accee
Merge branch 'main' into debuglogs
leochr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package common | ||
|
||
import ( | ||
"go.uber.org/zap/zapcore" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
|
@@ -17,6 +18,28 @@ const ( | |
|
||
// OpConfigCMCADuration default duration for cert-manager issued service certificate | ||
OpConfigCMCertDuration = "certManagerCertDuration" | ||
|
||
// OpConfigLogLevel the level of logs to be written | ||
OpConfigLogLevel = "logLevel" | ||
|
||
// The allowed values for OpConfigLogLevel | ||
logLevelWarning = "warning" | ||
logLevelInfo = "info" | ||
logLevelDebug = "debug" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought about the levels, I think naming similar to Liberty would be better. Suggest |
||
logLevelDebug2 = "debug2" | ||
logLevelDebugMax = "debugmax" | ||
|
||
// Constants to use when fetching a debug level logger | ||
LogLevelDebug = 1 | ||
LogLevelDebug2 = 2 | ||
|
||
// zap logging level constants | ||
zLevelWarn zapcore.Level = 1 | ||
zLevelInfo zapcore.Level = 0 | ||
zLevelDebug zapcore.Level = -1 | ||
zLevelDebug2 zapcore.Level = -2 | ||
// zapcore.Level is defined as int8, so this logs everything | ||
zLevelDebugMax zapcore.Level = -127 | ||
) | ||
|
||
// Config stores operator configuration | ||
|
@@ -33,11 +56,37 @@ func (oc OpConfig) LoadFromConfigMap(cm *corev1.ConfigMap) { | |
} | ||
} | ||
|
||
// Returns the zap log level corresponding to the value of the | ||
// 'logLevel' key in the config map. Returns 'info' if they key | ||
// is missing or contains an invalid value. | ||
func (oc OpConfig) GetZapLogLevel() zapcore.Level { | ||
level, ok := oc[OpConfigLogLevel] | ||
if !ok { | ||
return zLevelInfo | ||
} | ||
switch level { | ||
case logLevelWarning: | ||
return zLevelWarn | ||
case logLevelInfo: | ||
return zLevelInfo | ||
case logLevelDebug: | ||
return zLevelDebug | ||
case logLevelDebug2: | ||
return zLevelDebug2 | ||
case logLevelDebugMax: | ||
return zLevelDebugMax | ||
default: | ||
// config value is invalid. | ||
return zLevelInfo | ||
} | ||
} | ||
|
||
// DefaultOpConfig returns default configuration | ||
func DefaultOpConfig() OpConfig { | ||
cfg := OpConfig{} | ||
cfg[OpConfigDefaultHostname] = "" | ||
cfg[OpConfigCMCADuration] = "8766h" | ||
cfg[OpConfigCMCertDuration] = "2160h" | ||
cfg[OpConfigLogLevel] = logLevelInfo | ||
return cfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Suggest
operatorLogLevel
to avoid any confusion with app log level