50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package flag
|
|
|
|
import (
|
|
"fmt"
|
|
"gitea.illuad.fr/adrien/middleman"
|
|
"github.com/rs/zerolog"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
const (
|
|
LogFormatFlagName = "log-format"
|
|
LogLevelFlagName = "log-level"
|
|
)
|
|
|
|
const (
|
|
defaultLogFormat = "json"
|
|
defaultLogLevel = zerolog.ErrorLevel
|
|
)
|
|
|
|
// ErrInvalidLogLevel is returned if the given log level is invalid.
|
|
type ErrInvalidLogLevel struct {
|
|
LogLevel string
|
|
}
|
|
|
|
func (e ErrInvalidLogLevel) Error() string {
|
|
return fmt.Sprintf("%s: invalid log level, see help", e.LogLevel)
|
|
}
|
|
|
|
func LogFormat(parent string) cli.Flag {
|
|
return &cli.StringFlag{
|
|
Name: LogFormatFlagName,
|
|
Category: "log",
|
|
Usage: "log format (hf, json)",
|
|
Sources: middleman.PluckEnvVar("MIDDLEMAN", LogFormatFlagName),
|
|
Value: defaultLogFormat,
|
|
Aliases: middleman.PluckAlias(parent, LogFormatFlagName),
|
|
}
|
|
}
|
|
|
|
func LogLevel(parent string) cli.Flag {
|
|
return &cli.StringFlag{
|
|
Name: LogLevelFlagName,
|
|
Category: "log",
|
|
Usage: "log level (trace, debug, info, warn, error, fatal, panic)",
|
|
Sources: middleman.PluckEnvVar("MIDDLEMAN", LogLevelFlagName),
|
|
Value: defaultLogLevel.String(),
|
|
Aliases: middleman.PluckAlias(parent, LogLevelFlagName),
|
|
}
|
|
}
|