Clean up logger

This commit is contained in:
2025-12-13 13:18:30 +01:00
parent 4d57b37a5d
commit c0cecdd377
2 changed files with 12 additions and 12 deletions

View File

@@ -71,7 +71,7 @@ func New(name string, globalConfig *config.AppConfig, opts *Options, onStatusCha
if !instance.IsRemote() { if !instance.IsRemote() {
logRotationConfig := &LogRotationConfig{ logRotationConfig := &LogRotationConfig{
Enabled: globalInstanceSettings.LogRotationEnabled, Enabled: globalInstanceSettings.LogRotationEnabled,
MaxSizeMB: globalInstanceSettings.LogRotationMaxSize, MaxSize: globalInstanceSettings.LogRotationMaxSize,
Compress: globalInstanceSettings.LogRotationCompress, Compress: globalInstanceSettings.LogRotationCompress,
} }
instance.logger = newLogger( instance.logger = newLogger(

View File

@@ -14,9 +14,9 @@ import (
// LogRotationConfig contains log rotation settings for instances // LogRotationConfig contains log rotation settings for instances
type LogRotationConfig struct { type LogRotationConfig struct {
Enabled bool `yaml:"enabled" default:"true"` Enabled bool
MaxSizeMB int `yaml:"max_size_mb" default:"100"` // MB MaxSize int
Compress bool `yaml:"compress" default:"false"` Compress bool
} }
type logger struct { type logger struct {
@@ -54,8 +54,8 @@ func (l *logger) create() error {
// Build the timber logger // Build the timber logger
t := &timber.Logger{ t := &timber.Logger{
Filename: logPath, Filename: logPath,
MaxSize: l.cfg.MaxSizeMB, MaxSize: l.cfg.MaxSize,
MaxBackups: 0, // No limit on backups - use index-based naming MaxBackups: 0, // No limit on backups
// Compression: "gzip" if Compress is true, else "none" // Compression: "gzip" if Compress is true, else "none"
Compression: func() string { Compression: func() string {
if l.cfg.Compress { if l.cfg.Compress {
@@ -63,8 +63,8 @@ func (l *logger) create() error {
} }
return "none" return "none"
}(), }(),
FileMode: 0644, // default; timberjack uses 640 if 0 FileMode: 0644,
LocalTime: false, // Use index-based naming instead of timestamps LocalTime: true,
} }
// If rotation is disabled, set MaxSize to 0 so no rotation occurs // If rotation is disabled, set MaxSize to 0 so no rotation occurs
@@ -87,7 +87,7 @@ func (l *logger) readOutput(rc io.ReadCloser) {
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
if lg := l.logFile; lg != nil { if lg := l.logFile; lg != nil {
fmt.Fprintln(lg, line) // timber.Logger implements io.Writer fmt.Fprintln(lg, line)
} }
} }
} }
@@ -104,7 +104,7 @@ func (l *logger) close() {
ts := time.Now().Format("2006-01-02 15:04:05") ts := time.Now().Format("2006-01-02 15:04:05")
fmt.Fprintf(lg, "=== Instance %s stopped at %s ===\n\n", l.name, ts) fmt.Fprintf(lg, "=== Instance %s stopped at %s ===\n\n", l.name, ts)
_ = lg.Close() // shuts down any background goroutines (none in this config) _ = lg.Close()
l.logFile = nil l.logFile = nil
} }