MCPcopy
hub / github.com/kopia/kopia / initialize

Method initialize

internal/logfile/logfile.go:103–146  ·  view source on GitHub ↗

initialize is invoked as part of command execution to create log file just before it's needed.

(ctx *kingpin.ParseContext)

Source from the content-addressed store, hash-verified

101
102// initialize is invoked as part of command execution to create log file just before it's needed.
103func (c *loggingFlags) initialize(ctx *kingpin.ParseContext) error {
104 if c.logDir == "" {
105 return nil
106 }
107
108 now := clock.Now()
109 if c.fileLogLocalTimezone {
110 now = now.Local()
111 } else {
112 now = now.UTC()
113 }
114
115 suffix := "unknown"
116 if c := ctx.SelectedCommand; c != nil {
117 suffix = strings.ReplaceAll(c.FullCommand(), " ", "-")
118 }
119
120 rootCores := []zapcore.Core{c.setupConsoleCore()}
121 if !c.disableFileLogging {
122 rootCores = append(rootCores, c.setupLogFileCore(now, suffix))
123 }
124
125 rootLogger := zap.New(zapcore.NewTee(rootCores...), zap.WithClock(zaplogutil.Clock()))
126
127 var contentLogWriter io.Writer
128
129 if !c.disableFileLogging && !c.disableContentLogs {
130 contentLogWriter = c.setupLogFileBasedLogger(now, "content-logs", suffix, c.contentLogFile, c.contentLogDirMaxFiles, c.contentLogDirMaxTotalSizeMB, c.contentLogDirMaxAge)
131 }
132
133 c.cliApp.SetLoggerFactory(func(module string) logging.Logger {
134 return rootLogger.Named(module).Sugar()
135 }, contentLogWriter)
136
137 if c.forceColor {
138 color.NoColor = false
139 }
140
141 if c.disableColor {
142 color.NoColor = true
143 }
144
145 return nil
146}
147
148func (c *loggingFlags) setupConsoleCore() zapcore.Core {
149 ec := zapcore.EncoderConfig{

Callers

nothing calls this directly

Calls 6

setupConsoleCoreMethod · 0.95
setupLogFileCoreMethod · 0.95
NowFunction · 0.92
ClockFunction · 0.92
SetLoggerFactoryMethod · 0.80

Tested by

no test coverage detected