log: define OutputFormat type
Strong-type the format. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
778ac302b2
commit
dd67240f1b
@ -357,7 +357,7 @@ func setLogLevel(context *cli.Context, config *srvconfig.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setLogFormat(config *srvconfig.Config) error {
|
func setLogFormat(config *srvconfig.Config) error {
|
||||||
f := config.Debug.Format
|
f := log.OutputFormat(config.Debug.Format)
|
||||||
if f == "" {
|
if f == "" {
|
||||||
f = log.TextFormat
|
f = log.TextFormat
|
||||||
}
|
}
|
||||||
|
@ -96,17 +96,20 @@ func GetLevel() Level {
|
|||||||
return logrus.GetLevel()
|
return logrus.GetLevel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OutputFormat specifies a log output format.
|
||||||
|
type OutputFormat string
|
||||||
|
|
||||||
// Supported log output formats.
|
// Supported log output formats.
|
||||||
const (
|
const (
|
||||||
// TextFormat represents the text logging format.
|
// TextFormat represents the text logging format.
|
||||||
TextFormat = "text"
|
TextFormat OutputFormat = "text"
|
||||||
|
|
||||||
// JSONFormat represents the JSON logging format.
|
// JSONFormat represents the JSON logging format.
|
||||||
JSONFormat = "json"
|
JSONFormat OutputFormat = "json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetFormat sets the log output format ([TextFormat] or [JSONFormat]).
|
// SetFormat sets the log output format ([TextFormat] or [JSONFormat]).
|
||||||
func SetFormat(format string) error {
|
func SetFormat(format OutputFormat) error {
|
||||||
switch format {
|
switch format {
|
||||||
case TextFormat:
|
case TextFormat:
|
||||||
logrus.SetFormatter(&logrus.TextFormatter{
|
logrus.SetFormatter(&logrus.TextFormatter{
|
||||||
|
Loading…
Reference in New Issue
Block a user