mirror of
https://github.com/kopia/kopia.git
synced 2026-05-11 00:04:46 -04:00
Turns out standard ConsoleEncoder is not optimized at all and we're emitting up to 8 log entries per file. This change avoids massive amount of allocations and brings in some latency reduction. Backing up 100k files in a flat directory: duration: current:7.8 baseline:7.9 change:-1.0 % repo_size: current:1019954521.4 baseline:1019976318.9 change:-0.0 % num_files: current:58.0 baseline:58.0 change:0% avg_heap_objects: current:6682141.0 baseline:7508631.3 change:-11.0 % avg_heap_bytes: current:845404672.0 baseline:867325413.9 change:-2.5 % avg_ram: current:156.5 baseline:159.1 change:-1.7 % max_ram: current:278.3 baseline:287.2 change:-3.1 % avg_cpu: current:153.8 baseline:156.4 change:-1.7 % max_cpu: current:298.4 baseline:297.1 change:+0.4 % Backing up Linux 5.18.4: duration: current:3.6 baseline:4.2 change:-14.2 % repo_size: current:1081624213.7 baseline:1081635886.8 change:-0.0 % num_files: current:60.0 baseline:60.0 change:0% avg_heap_objects: current:5180192.3 baseline:5831270.7 change:-11.2 % avg_heap_bytes: current:783468754.2 baseline:804350042.1 change:-2.6 % avg_ram: current:239.0 baseline:240.6 change:-0.6 % max_ram: current:384.8 baseline:368.0 change:+4.6 % avg_cpu: current:259.8 baseline:230.8 change:+12.6 % max_cpu: current:321.6 baseline:303.9 change:+5.9 %
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
// Package logging provides loggers for Kopia.
|
|
package logging
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
|
|
"github.com/kopia/kopia/internal/zaplogutil"
|
|
)
|
|
|
|
// Logger is used by Kopia to emit various logs.
|
|
type Logger = *zap.SugaredLogger
|
|
|
|
// LoggerFactory retrieves a named logger for a given module.
|
|
type LoggerFactory func(module string) Logger
|
|
|
|
// Module returns an function that returns a logger for a given module when provided with a context.
|
|
func Module(module string) func(ctx context.Context) Logger {
|
|
return func(ctx context.Context) Logger {
|
|
if l := ctx.Value(loggerCacheKey); l != nil {
|
|
return l.(*loggerCache).getLogger(module) //nolint:forcetypeassert
|
|
}
|
|
|
|
return NullLogger
|
|
}
|
|
}
|
|
|
|
// ToWriter returns LoggerFactory that uses given writer for log output (unadorned).
|
|
func ToWriter(w io.Writer) LoggerFactory {
|
|
return zap.New(zapcore.NewCore(
|
|
zaplogutil.NewStdConsoleEncoder(zaplogutil.StdConsoleEncoderConfig{}),
|
|
zapcore.AddSync(w), zap.DebugLevel), zap.WithClock(zaplogutil.Clock())).Sugar().Named
|
|
}
|