| 272 | } |
| 273 | |
| 274 | func ChangeLogLevel(level zapcore.Level) (*zap.Logger, error) { |
| 275 | LogCfg.Level = zap.NewAtomicLevelAt(level) |
| 276 | if level == zap.DebugLevel { |
| 277 | LogCfg.DisableStacktrace = false |
| 278 | LogCfg.EncoderConfig.EncodeCaller = zapcore.ShortCallerEncoder |
| 279 | } |
| 280 | |
| 281 | // Use our custom encoder when building |
| 282 | encoder := NewANSIConsoleEncoder(LogCfg.EncoderConfig) |
| 283 | core := zapcore.NewCore( |
| 284 | encoder, |
| 285 | wrapWriter(zapcore.AddSync(os.Stdout)), |
| 286 | LogCfg.Level, |
| 287 | ) |
| 288 | |
| 289 | logger := zap.New(newRedactingCore(core)) |
| 290 | return reattachDebugFileSink(logger), nil |
| 291 | } |
| 292 | |
| 293 | // RedirectToStderr re-creates the logger writing to stderr instead of stdout. |
| 294 | // Use this when --json mode is active to prevent log lines from contaminating |