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

Method NewAccessLogger

pkg/csconfig/api.go:252–272  ·  view source on GitHub ↗

NewAccessLogger builds and returns a logger configured for HTTP access logging using the provided log configuration. If log_media is "file", the access log is written to the provided filename inside LogDir. For "stdout" or "syslog", the access logger uses the same output destination as the standard

(cfg LogConfig, filename string)

Source from the content-addressed store, hash-verified

250// inside LogDir. For "stdout" or "syslog", the access logger uses the same
251// output destination as the standard logger.
252func (c *LocalApiServerCfg) NewAccessLogger(cfg LogConfig, filename string) *log.Entry {
253 media := cfg.GetMedia()
254 logger := log.WithField("output", media)
255
256 defer func() {
257 logger.Debug("starting access logger")
258 }()
259
260 accessLogger := logging.SubLogger(log.StandardLogger(), "lapi", c.LogLevel)
261
262 if media != "file" {
263 return accessLogger
264 }
265
266 logPath := filepath.Join(cfg.GetDir(), filename)
267 logger = logger.WithField("file", logPath)
268
269 accessLogger.Logger.SetOutput(cfg.NewRotatingLogger(filename))
270
271 return accessLogger
272}
273
274func (c *LocalApiServerCfg) NewPAPILogger() *log.Entry {
275 level := cmp.Or(c.PapiLogLevel, c.LogLevel)

Callers 1

initAPIServerFunction · 0.80

Calls 6

SubLoggerFunction · 0.92
StandardLoggerMethod · 0.80
GetDirMethod · 0.80
GetMediaMethod · 0.65
NewRotatingLoggerMethod · 0.65
DebugMethod · 0.45

Tested by

no test coverage detected