Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 32c8321

Browse files
authored
Merge pull request #38 from kappnav/171-fixWhenNoLoggingInfoInCR
Issue#171: fix set logging level when no logging info in kappnav CR
2 parents 12f25f0 + 152bae3 commit 32c8321

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

kappnav_handler.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,16 @@ func parseKAppNavResource(resource interface{}, kappnavResource *KappnavResource
126126
loggingMap, _ := spec["logging"]
127127
// retrieve logging value of "controller" from logging map
128128
if loggingMap != nil {
129-
loggingValue := loggingMap.(map[string]interface{})["controller"].(string)
130-
if len(loggingValue) > 0 {
131-
if logger.IsEnabled(LogTypeInfo) {
132-
logger.Log(CallerName(), LogTypeInfo, "Set the log level to "+loggingValue)
129+
loggingValue := loggingMap.(map[string]interface{})["controller"]
130+
if loggingValue != nil {
131+
loggingValue := loggingValue.(string)
132+
if len(loggingValue) > 0 {
133+
if logger.IsEnabled(LogTypeInfo) {
134+
logger.Log(CallerName(), LogTypeInfo, "Set the log level to "+loggingValue)
135+
}
136+
//invoke setLoggingLevel to reset log level
137+
SetLoggingLevel(loggingValue)
133138
}
134-
//invoke setLoggingLevel to reset log level
135-
SetLoggingLevel(loggingValue)
136139
}
137140
}
138141

main.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,16 @@ func setInitLoggingData(dynInterf dynamic.Interface) {
203203
loggingMap, _ := spec["logging"]
204204
// retrieve logging value of "controller" from logging map
205205
if loggingMap != nil {
206-
loggingValue := loggingMap.(map[string]interface{})["controller"].(string)
207-
if len(loggingValue) > 0 {
208-
if logger.IsEnabled(LogTypeInfo) {
209-
logger.Log(CallerName(), LogTypeInfo, "Set the log level to "+loggingValue)
206+
loggingValue := loggingMap.(map[string]interface{})["controller"]
207+
if loggingValue != nil {
208+
loggingValue := loggingValue.(string)
209+
if len(loggingValue) > 0 {
210+
if logger.IsEnabled(LogTypeInfo) {
211+
logger.Log(CallerName(), LogTypeInfo, "Set the log level to "+loggingValue)
212+
}
213+
//invoke setLoggingLevel to reset log level
214+
SetLoggingLevel(loggingValue)
210215
}
211-
//invoke setLoggingLevel to reset log level
212-
SetLoggingLevel(loggingValue)
213216
}
214217
}
215218
}

0 commit comments

Comments
 (0)