Skip to content

Commit

Permalink
Merge pull request #34 from xhebox/rework_0
Browse files Browse the repository at this point in the history
export text core
  • Loading branch information
hawkingrei authored Nov 16, 2022
2 parents 21a4942 + 547743a commit 734d527
Showing 1 changed file with 16 additions and 16 deletions.
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

0 comments on commit 734d527

Please sign in to comment.