log: define OutputFormat type

Strong-type the format.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-16 22:32:38 +02:00
parent 778ac302b2
commit dd67240f1b
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 7 additions and 4 deletions

View File

@ -357,7 +357,7 @@ func setLogLevel(context *cli.Context, config *srvconfig.Config) error {
}
func setLogFormat(config *srvconfig.Config) error {
f := config.Debug.Format
f := log.OutputFormat(config.Debug.Format)
if f == "" {
f = log.TextFormat
}

View File

@ -96,17 +96,20 @@ func GetLevel() Level {
return logrus.GetLevel()
}
// OutputFormat specifies a log output format.
type OutputFormat string
// Supported log output formats.
const (
// TextFormat represents the text logging format.
TextFormat = "text"
TextFormat OutputFormat = "text"
// JSONFormat represents the JSON logging format.
JSONFormat = "json"
JSONFormat OutputFormat = "json"
)
// SetFormat sets the log output format ([TextFormat] or [JSONFormat]).
func SetFormat(format string) error {
func SetFormat(format OutputFormat) error {
switch format {
case TextFormat:
logrus.SetFormatter(&logrus.TextFormatter{