Skip to content

Commit dd12788

Browse files
committed
log: define OutputFormat type
Strong-type the format. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit dd67240) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 5b4cf23 commit dd12788

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

cmd/containerd/command/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func setLogLevel(context *cli.Context, config *srvconfig.Config) error {
352352
}
353353

354354
func setLogFormat(config *srvconfig.Config) error {
355-
f := config.Debug.Format
355+
f := log.OutputFormat(config.Debug.Format)
356356
if f == "" {
357357
f = log.TextFormat
358358
}

log/context.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,20 @@ func GetLevel() Level {
9696
return logrus.GetLevel()
9797
}
9898

99+
// OutputFormat specifies a log output format.
100+
type OutputFormat string
101+
99102
// Supported log output formats.
100103
const (
101104
// TextFormat represents the text logging format.
102-
TextFormat = "text"
105+
TextFormat OutputFormat = "text"
103106

104107
// JSONFormat represents the JSON logging format.
105-
JSONFormat = "json"
108+
JSONFormat OutputFormat = "json"
106109
)
107110

108111
// SetFormat sets the log output format ([TextFormat] or [JSONFormat]).
109-
func SetFormat(format string) error {
112+
func SetFormat(format OutputFormat) error {
110113
switch format {
111114
case TextFormat:
112115
logrus.SetFormatter(&logrus.TextFormatter{

0 commit comments

Comments
 (0)