mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-09-20 16:37:19 +02:00
feat: persist diagnostic logs with daily rotation and retention
This commit is contained in:
@@ -11,7 +11,7 @@ type Logger struct {
|
||||
*zap.Logger
|
||||
}
|
||||
|
||||
func New(level, output string) *Logger {
|
||||
func New(level, output string, diagnostics ...DiagnosticOptions) *Logger {
|
||||
var zapLevel zapcore.Level
|
||||
switch level {
|
||||
case "debug":
|
||||
@@ -34,6 +34,8 @@ func New(level, output string) *Logger {
|
||||
var writeSyncer zapcore.WriteSyncer
|
||||
if output == "stdout" {
|
||||
writeSyncer = zapcore.AddSync(os.Stdout)
|
||||
} else if output == "stderr" {
|
||||
writeSyncer = zapcore.AddSync(os.Stderr)
|
||||
} else {
|
||||
file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
@@ -49,6 +51,18 @@ func New(level, output string) *Logger {
|
||||
zapLevel,
|
||||
)
|
||||
|
||||
options := DiagnosticOptions{}
|
||||
if len(diagnostics) > 0 {
|
||||
options = diagnostics[0]
|
||||
}
|
||||
if !options.Disabled {
|
||||
// The diagnostic threshold is independent of the primary output level.
|
||||
core = zapcore.NewTee(core, zapcore.NewCore(
|
||||
zapcore.NewJSONEncoder(config.EncoderConfig),
|
||||
newDailyWriter(options), zapcore.WarnLevel,
|
||||
))
|
||||
}
|
||||
|
||||
logger := zap.New(core, zap.AddCaller(), zap.AddStacktrace(zapcore.ErrorLevel))
|
||||
|
||||
return &Logger{Logger: logger}
|
||||
|
||||
Reference in New Issue
Block a user