MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / InitLogging

Function InitLogging

base/logging_config.go:67–147  ·  view source on GitHub ↗
(ctx context.Context, logFilePath string,
	console *ConsoleLoggerConfig,
	error, warn, info, debug, trace, stats *FileLoggerConfig,
	audit *AuditLoggerConfig, auditLogGlobalFields map[string]any)

Source from the content-addressed store, hash-verified

65}
66
67func InitLogging(ctx context.Context, logFilePath string,
68 console *ConsoleLoggerConfig,
69 error, warn, info, debug, trace, stats *FileLoggerConfig,
70 audit *AuditLoggerConfig, auditLogGlobalFields map[string]any) (err error) {
71
72 rawConsoleLogger, err := NewConsoleLogger(ctx, true, console)
73 if err != nil {
74 return err
75 }
76 consoleLogger.Store(rawConsoleLogger)
77
78 // If there's nowhere to specified put log files, we'll log an error, but continue anyway.
79 if logFilePath == "" {
80 ConsolefCtx(ctx, LevelInfo, KeyNone, "Logging: Files disabled")
81 // Explicitly log this error to console
82 ConsolefCtx(ctx, LevelError, KeyNone, "%s", ErrUnsetLogFilePath.Error())
83 nilAllNonConsoleLoggers()
84 return nil
85 }
86
87 ConsolefCtx(ctx, LevelInfo, KeyNone, "Logging: Files to %v", logFilePath)
88
89 auditLogFilePath := logFilePath
90 if audit != nil && audit.AuditLogFilePath != nil && ValDefault(audit.Enabled, false) {
91 auditLogFilePath = *audit.AuditLogFilePath
92 ConsolefCtx(ctx, LevelInfo, KeyNone, "Logging: Audit to %v", auditLogFilePath)
93 }
94
95 rawErrorlogger, err := NewFileLogger(ctx, error, LevelError, LevelError.String(), logFilePath, errorMinAge, nil, &errorLogger.Load().buffer)
96 if err != nil {
97 return err
98 }
99 errorLogger.Store(rawErrorlogger)
100
101 rawWarnLogger, err := NewFileLogger(ctx, warn, LevelWarn, LevelWarn.String(), logFilePath, warnMinAge, nil, &warnLogger.Load().buffer)
102 if err != nil {
103 return err
104 }
105 warnLogger.Store(rawWarnLogger)
106
107 rawInfoLogger, err := NewFileLogger(ctx, info, LevelInfo, LevelInfo.String(), logFilePath, infoMinAge, nil, &infoLogger.Load().buffer)
108 if err != nil {
109 return err
110 }
111 infoLogger.Store(rawInfoLogger)
112
113 rawDebugLogger, err := NewFileLogger(ctx, debug, LevelDebug, LevelDebug.String(), logFilePath, debugMinAge, nil, &debugLogger.Load().buffer)
114 if err != nil {
115 return err
116 }
117 debugLogger.Store(rawDebugLogger)
118
119 rawTraceLogger, err := NewFileLogger(ctx, trace, LevelTrace, LevelTrace.String(), logFilePath, traceMinAge, nil, &traceLogger.Load().buffer)
120 if err != nil {
121 return err
122 }
123 traceLogger.Store(rawTraceLogger)
124

Callers 1

Calls 12

NewConsoleLoggerFunction · 0.85
ConsolefCtxFunction · 0.85
nilAllNonConsoleLoggersFunction · 0.85
ValDefaultFunction · 0.85
NewFileLoggerFunction · 0.85
PtrFunction · 0.85
NewAuditLoggerFunction · 0.85
initExternalLoggersFunction · 0.85
StoreMethod · 0.80
LoadMethod · 0.80
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected