Skip to content

Commit

Permalink
log: define OutputFormat type
Browse files Browse the repository at this point in the history
Strong-type the format.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit dd67240)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Sep 8, 2023
1 parent 5b4cf23 commit dd12788
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/containerd/command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,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
}
Expand Down
9 changes: 6 additions & 3 deletions log/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit dd12788

Please sign in to comment.