Logger returns a logger that is ready for the module to use.
(mod Module)
| 217 | |
| 218 | // Logger returns a logger that is ready for the module to use. |
| 219 | func (logging *Logging) Logger(mod Module) *zap.Logger { |
| 220 | modID := string(mod.CaddyModule().ID) |
| 221 | var cores []zapcore.Core |
| 222 | var options []zap.Option |
| 223 | |
| 224 | if logging != nil { |
| 225 | for _, l := range logging.Logs { |
| 226 | if l.matchesModule(modID) { |
| 227 | if len(l.Include) == 0 && len(l.Exclude) == 0 { |
| 228 | cores = append(cores, l.core) |
| 229 | continue |
| 230 | } |
| 231 | if len(options) == 0 { |
| 232 | newOptions, err := l.buildOptions() |
| 233 | if err != nil { |
| 234 | Log().Error("building options for logger", zap.String("module", modID), zap.Error(err)) |
| 235 | } |
| 236 | options = newOptions |
| 237 | } |
| 238 | cores = append(cores, &filteringCore{Core: l.core, cl: l}) |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | multiCore := zapcore.NewTee(cores...) |
| 244 | |
| 245 | return zap.New(multiCore, options...).Named(modID) |
| 246 | } |
| 247 | |
| 248 | // openWriter opens a writer using opener, and returns true if |
| 249 | // the writer is new, or false if the writer already exists. |
no test coverage detected