github.com/TBD54566975/ftl@v0.219.0/internal/log/configure.go (about) 1 package log 2 3 import ( 4 "io" 5 ) 6 7 // Config for the logger. 8 type Config struct { 9 Level Level `help:"Log level." default:"info" env:"LOG_LEVEL"` 10 JSON bool `help:"Log in JSON format." env:"LOG_JSON"` 11 Timestamps bool `help:"Include timestamps in text logs." env:"LOG_TIMESTAMPS"` 12 Color bool `help:"Enable colored output regardless of TTY." env:"LOG_COLOR"` 13 } 14 15 // Configure returns a new logger based on the config. 16 func Configure(w io.Writer, cfg Config) *Logger { 17 var sink Sink 18 if cfg.JSON { 19 sink = newJSONSink(w) 20 } else { 21 sink = newPlainSink(w, cfg.Timestamps, cfg.Color) 22 } 23 return New(cfg.Level, sink) 24 }