RegisterEncoder registers an encoder constructor, which the Config struct can then reference. By default, the "json" and "console" encoders are registered. Attempting to register an encoder whose name is already taken returns an error.
(name string, constructor func(zapcore.EncoderConfig) (zapcore.Encoder, error))
| 49 | // Attempting to register an encoder whose name is already taken returns an |
| 50 | // error. |
| 51 | func RegisterEncoder(name string, constructor func(zapcore.EncoderConfig) (zapcore.Encoder, error)) error { |
| 52 | _encoderMutex.Lock() |
| 53 | defer _encoderMutex.Unlock() |
| 54 | if name == "" { |
| 55 | return errNoEncoderNameSpecified |
| 56 | } |
| 57 | if _, ok := _encoderNameToConstructor[name]; ok { |
| 58 | return fmt.Errorf("encoder already registered for name %q", name) |
| 59 | } |
| 60 | _encoderNameToConstructor[name] = constructor |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | func newEncoder(name string, encoderConfig zapcore.EncoderConfig) (zapcore.Encoder, error) { |
| 65 | if encoderConfig.TimeKey != "" && encoderConfig.EncodeTime == nil { |