-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored logging configuration setup
The default logging configuration has been refactored to support both console and file logging. The logic for generating the default config has been moved from main.go to a new file, server/logging.go. This change allows the application to dynamically choose between console or file logging based on the 'EnableFileLog' flag in the configuration.
- Loading branch information
1 parent
8e38a57
commit bd90d26
Showing
2 changed files
with
75 additions
and
29 deletions.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func DefaultLoggingConfig(cfg *ConfigPushProxy) string { | ||
if cfg.EnableFileLog == false { | ||
return defaultLoggingConsoleLogConfig() | ||
} else { | ||
return defaultLoggingFileLogConfig(cfg.LogFileLocation) | ||
} | ||
} | ||
|
||
func defaultLoggingFileLogConfig(filename string) string { | ||
return fmt.Sprintf(` | ||
{ | ||
"def": { | ||
"type": "file", | ||
"options": { | ||
"filename": "%s" | ||
}, | ||
"format": "plain", | ||
"format_options": { | ||
"delim": " ", | ||
"min_level_len": 5, | ||
"min_msg_len": 40, | ||
"enable_color": true, | ||
"enable_caller": true | ||
}, | ||
"levels": [ | ||
{"id": 5, "name": "debug"}, | ||
{"id": 4, "name": "info", "color": 36}, | ||
{"id": 3, "name": "warn"}, | ||
{"id": 2, "name": "error", "color": 31}, | ||
{"id": 1, "name": "fatal", "stacktrace": true}, | ||
{"id": 0, "name": "panic", "stacktrace": true} | ||
] | ||
} | ||
}`, escapeDoubleQuotes(filename)) | ||
} | ||
|
||
func defaultLoggingConsoleLogConfig() string { | ||
return ` | ||
{ | ||
"def": { | ||
"type": "console", | ||
"options": { | ||
"out": "stdout" | ||
}, | ||
"format": "plain", | ||
"format_options": { | ||
"delim": " ", | ||
"min_level_len": 5, | ||
"min_msg_len": 40, | ||
"enable_color": true, | ||
"enable_caller": true | ||
}, | ||
"levels": [ | ||
{"id": 5, "name": "debug"}, | ||
{"id": 4, "name": "info", "color": 36}, | ||
{"id": 3, "name": "warn"}, | ||
{"id": 2, "name": "error", "color": 31}, | ||
{"id": 1, "name": "fatal", "stacktrace": true}, | ||
{"id": 0, "name": "panic", "stacktrace": true} | ||
] | ||
} | ||
}` | ||
} | ||
|
||
func escapeDoubleQuotes(input string) string { | ||
return strings.ReplaceAll(input, `"`, `\"`) | ||
} |