Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export text core #34

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions zap_text_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ import (
"go.uber.org/zap/zapcore"
)

// TextIOCore is a copy of zapcore.ioCore that only accept *textEncoder
// it can be removed after https://github.com/uber-go/zap/pull/685 be merged
type TextIOCore struct {
zapcore.LevelEnabler
enc zapcore.Encoder
out zapcore.WriteSyncer
}

// NewTextCore creates a Core that writes logs to a WriteSyncer.
func NewTextCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core {
return &textIOCore{
return &TextIOCore{
LevelEnabler: enab,
enc: enc,
out: ws,
}
}

// textIOCore is a copy of zapcore.ioCore that only accept *textEncoder
// it can be removed after https://github.com/uber-go/zap/pull/685 be merged
type textIOCore struct {
zapcore.LevelEnabler
enc zapcore.Encoder
out zapcore.WriteSyncer
}

func (c *textIOCore) With(fields []zapcore.Field) zapcore.Core {
clone := c.clone()
func (c *TextIOCore) With(fields []zapcore.Field) zapcore.Core {
clone := c.Clone()
// it's different to ioCore, here call textEncoder#addFields to fix https://github.com/pingcap/log/issues/3
switch e := clone.enc.(type) {
case *textEncoder:
Expand All @@ -53,14 +53,14 @@ func (c *textIOCore) With(fields []zapcore.Field) zapcore.Core {
return clone
}

func (c *textIOCore) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
func (c *TextIOCore) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
if c.Enabled(ent.Level) {
return ce.AddCore(ent, c)
}
return ce
}

func (c *textIOCore) Write(ent zapcore.Entry, fields []zapcore.Field) error {
func (c *TextIOCore) Write(ent zapcore.Entry, fields []zapcore.Field) error {
buf, err := c.enc.EncodeEntry(ent, fields)
if err != nil {
return err
Expand All @@ -78,12 +78,12 @@ func (c *textIOCore) Write(ent zapcore.Entry, fields []zapcore.Field) error {
return nil
}

func (c *textIOCore) Sync() error {
func (c *TextIOCore) Sync() error {
return c.out.Sync()
}

func (c *textIOCore) clone() *textIOCore {
return &textIOCore{
func (c *TextIOCore) Clone() *TextIOCore {
return &TextIOCore{
LevelEnabler: c.LevelEnabler,
enc: c.enc.Clone(),
out: c.out,
Expand Down