ZapcoreEncoderConfig returns the equivalent zapcore.EncoderConfig. If lec is nil, zap.NewProductionEncoderConfig() is returned.
()
| 201 | // ZapcoreEncoderConfig returns the equivalent zapcore.EncoderConfig. |
| 202 | // If lec is nil, zap.NewProductionEncoderConfig() is returned. |
| 203 | func (lec *LogEncoderConfig) ZapcoreEncoderConfig() zapcore.EncoderConfig { |
| 204 | cfg := zap.NewProductionEncoderConfig() |
| 205 | if lec == nil { |
| 206 | lec = new(LogEncoderConfig) |
| 207 | } |
| 208 | if lec.MessageKey != nil { |
| 209 | cfg.MessageKey = *lec.MessageKey |
| 210 | } |
| 211 | if lec.LevelKey != nil { |
| 212 | cfg.LevelKey = *lec.LevelKey |
| 213 | } |
| 214 | if lec.TimeKey != nil { |
| 215 | cfg.TimeKey = *lec.TimeKey |
| 216 | } |
| 217 | if lec.NameKey != nil { |
| 218 | cfg.NameKey = *lec.NameKey |
| 219 | } |
| 220 | if lec.CallerKey != nil { |
| 221 | cfg.CallerKey = *lec.CallerKey |
| 222 | } |
| 223 | if lec.StacktraceKey != nil { |
| 224 | cfg.StacktraceKey = *lec.StacktraceKey |
| 225 | } |
| 226 | if lec.LineEnding != nil { |
| 227 | cfg.LineEnding = *lec.LineEnding |
| 228 | } |
| 229 | |
| 230 | // time format |
| 231 | var timeFormatter zapcore.TimeEncoder |
| 232 | switch lec.TimeFormat { |
| 233 | case "", "unix_seconds_float": |
| 234 | timeFormatter = zapcore.EpochTimeEncoder |
| 235 | case "unix_milli_float": |
| 236 | timeFormatter = zapcore.EpochMillisTimeEncoder |
| 237 | case "unix_nano": |
| 238 | timeFormatter = zapcore.EpochNanosTimeEncoder |
| 239 | case "iso8601": |
| 240 | timeFormatter = zapcore.ISO8601TimeEncoder |
| 241 | default: |
| 242 | timeFormat := lec.TimeFormat |
| 243 | switch lec.TimeFormat { |
| 244 | case "rfc3339": |
| 245 | timeFormat = time.RFC3339 |
| 246 | case "rfc3339_nano": |
| 247 | timeFormat = time.RFC3339Nano |
| 248 | case "wall": |
| 249 | timeFormat = "2006/01/02 15:04:05" |
| 250 | case "wall_milli": |
| 251 | timeFormat = "2006/01/02 15:04:05.000" |
| 252 | case "wall_nano": |
| 253 | timeFormat = "2006/01/02 15:04:05.000000000" |
| 254 | case "common_log": |
| 255 | timeFormat = "02/Jan/2006:15:04:05 -0700" |
| 256 | } |
| 257 | timeFormatter = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) { |
| 258 | var time time.Time |
| 259 | if lec.TimeLocal { |
| 260 | time = ts.Local() |