Skip to content

Commit

Permalink
zapcore: LineEnding logic moved to newJSONEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
lruggieri committed Nov 9, 2021
1 parent 9118565 commit 6fa2cff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
8 changes: 1 addition & 7 deletions zapcore/console_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,7 @@ func (c consoleEncoder) EncodeEntry(ent Entry, fields []Field) (*buffer.Buffer,
line.AppendString(ent.Stack)
}

if !c.SkipLineEnding {
if c.LineEnding != "" {
line.AppendString(c.LineEnding)
} else {
line.AppendString(DefaultLineEnding)
}
}
line.AppendString(c.LineEnding)
return line, nil
}

Expand Down
14 changes: 7 additions & 7 deletions zapcore/json_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func NewJSONEncoder(cfg EncoderConfig) Encoder {
}

func newJSONEncoder(cfg EncoderConfig, spaced bool) *jsonEncoder {
if cfg.SkipLineEnding {
cfg.LineEnding = ""
} else if cfg.LineEnding == "" {
cfg.LineEnding = DefaultLineEnding
}

return &jsonEncoder{
EncoderConfig: &cfg,
buf: bufferpool.Get(),
Expand Down Expand Up @@ -396,13 +402,7 @@ func (enc *jsonEncoder) EncodeEntry(ent Entry, fields []Field) (*buffer.Buffer,
final.AddString(final.StacktraceKey, ent.Stack)
}
final.buf.AppendByte('}')
if !final.SkipLineEnding {
if final.LineEnding != "" {
final.buf.AppendString(final.LineEnding)
} else {
final.buf.AppendString(DefaultLineEnding)
}
}
final.buf.AppendString(final.LineEnding)

ret := final.buf
putJSONEncoder(final)
Expand Down

0 comments on commit 6fa2cff

Please sign in to comment.