MCPcopy
hub / github.com/crowdsecurity/crowdsec / SubLogger

Function SubLogger

pkg/logging/sublogger.go:13–39  ·  view source on GitHub ↗

SubLogger creates a logrus.Entry object that inherits the formatter, output, and hooks from the given base logger, but can have a different log level and optional module field. If module == "", no field is added. If level == 0 (panic), the log level is inherited too.

(base *logrus.Logger, module string, level logrus.Level)

Source from the content-addressed store, hash-verified

11// If module == "", no field is added.
12// If level == 0 (panic), the log level is inherited too.
13func SubLogger(base *logrus.Logger, module string, level logrus.Level) *logrus.Entry {
14 l := logrus.New()
15 l.SetFormatter(base.Formatter)
16 l.SetOutput(base.Out)
17
18 for _, hooks := range base.Hooks {
19 for _, h := range hooks {
20 l.AddHook(h)
21 }
22 }
23
24 if level == 0 {
25 level = base.GetLevel()
26 }
27
28 l.SetLevel(level)
29
30 var fields logrus.Fields
31
32 if module != "" {
33 fields = logrus.Fields{
34 "module": module,
35 }
36 }
37
38 return l.WithFields(fields)
39}

Callers 11

NewLoggerMethod · 0.92
InitCrowdsecCTIFunction · 0.92
DataSourceConfigureFunction · 0.92
NewProfileFunction · 0.92
compileMethod · 0.92
bucketLoggerFunction · 0.92
NewServerFunction · 0.92
NewAccessLoggerMethod · 0.92
NewPAPILoggerMethod · 0.92
NewLoggerMethod · 0.92

Calls 2

GetLevelMethod · 0.80
SetLevelMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…