skip log writes if max retention setting is zero
This commit is contained in:
parent
b29e404f22
commit
97345f0317
|
@ -1186,10 +1186,11 @@ func (app *BaseApp) initLogger() error {
|
||||||
BatchSize: 200,
|
BatchSize: 200,
|
||||||
BeforeAddFunc: func(ctx context.Context, log *logger.Log) bool {
|
BeforeAddFunc: func(ctx context.Context, log *logger.Log) bool {
|
||||||
ticker.Reset(duration)
|
ticker.Reset(duration)
|
||||||
return true
|
|
||||||
|
return app.Settings().Logs.MaxDays > 0
|
||||||
},
|
},
|
||||||
WriteFunc: func(ctx context.Context, logs []*logger.Log) error {
|
WriteFunc: func(ctx context.Context, logs []*logger.Log) error {
|
||||||
if !app.IsBootstrapped() {
|
if !app.IsBootstrapped() || app.Settings().Logs.MaxDays == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -288,16 +288,31 @@ func TestBaseAppLoggerWrites(t *testing.T) {
|
||||||
t.Fatalf("Logs migration execution error: %v", err)
|
t.Fatalf("Logs migration execution error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
threshold := 200
|
||||||
|
|
||||||
|
// disabled logs retention
|
||||||
|
{
|
||||||
|
app.Settings().Logs.MaxDays = 0
|
||||||
|
|
||||||
|
for i := 0; i < threshold+1; i++ {
|
||||||
|
app.Logger().Error("test")
|
||||||
|
}
|
||||||
|
|
||||||
|
if total := totalLogs(app, t); total != 0 {
|
||||||
|
t.Fatalf("Expected no logs, got %d", total)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// test batch logs writes
|
// test batch logs writes
|
||||||
{
|
{
|
||||||
threshold := 200
|
app.Settings().Logs.MaxDays = 1
|
||||||
|
|
||||||
for i := 0; i < threshold-1; i++ {
|
for i := 0; i < threshold-1; i++ {
|
||||||
app.Logger().Error("test")
|
app.Logger().Error("test")
|
||||||
}
|
}
|
||||||
|
|
||||||
if total := totalLogs(app, t); total != 0 {
|
if total := totalLogs(app, t); total != 0 {
|
||||||
t.Fatalf("Expected %d logs, got %d", 0, total)
|
t.Fatalf("Expected no logs, got %d", total)
|
||||||
}
|
}
|
||||||
|
|
||||||
// should trigger batch write
|
// should trigger batch write
|
||||||
|
|
Loading…
Reference in New Issue