Skip to content

Commit

Permalink
添加root Logger meta
Browse files Browse the repository at this point in the history
  • Loading branch information
yumaojun03 committed Apr 14, 2020
1 parent bce8a33 commit 36296fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
40 changes: 21 additions & 19 deletions logger/zap/config.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@

package zap

import (
"time"

"go.uber.org/zap"
)

// Config contains the configuration options for the logger. To create a Config
// from a common.Config use logp/config.Build.
type Config struct {
Name string `config:",ignore"` // Name of the Logger (for default file name).
JSON bool `config:"json"` // Write logs as JSON.
Level Level `config:"level"` // Logging level (error, warning, info, debug).
Selectors []string `config:"selectors"` // Selectors for debug level logging.

ToStderr bool `config:"to_stderr"`
ToSyslog bool `config:"to_syslog"`
ToFiles bool `config:"to_files"`
ToEventLog bool `config:"to_eventlog"`
Name string // Name of the Logger (for default file name).
JSON bool // Write logs as JSON.
Level Level // Logging level (error, warning, info, debug).
Metas []zap.Field // Root Logger Metas
Selectors []string // Selectors for debug level logging.

ToStderr bool
ToSyslog bool
ToFiles bool
ToEventLog bool
toObserver bool
toIODiscard bool

Files FileConfig `config:"files"`
Files FileConfig

addCaller bool // Adds package and line number info to messages.
development bool // Controls how DPanic behaves.
}

// FileConfig contains the configuration options for the file output.
type FileConfig struct {
Path string `config:"path"`
Name string `config:"name"`
MaxSize uint `config:"rotateeverybytes" validate:"min=1"`
MaxBackups uint `config:"keepfiles" validate:"max=1024"`
Permissions uint32 `config:"permissions"`
Interval time.Duration `config:"interval"`
RotateOnStartup bool `config:"rotateonstartup"`
RedirectStderr bool `config:"redirect_stderr"`
Path string
Name string
MaxSize uint
MaxBackups uint
Permissions uint32
Interval time.Duration
RotateOnStartup bool
RedirectStderr bool
}

var defaultConfig = Config{
Expand Down
5 changes: 5 additions & 0 deletions logger/zap/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ func makeOptions(cfg Config) []zap.Option {
if cfg.development {
options = append(options, zap.Development())
}

if len(cfg.Metas) > 0 {
options = append(options, zap.Fields(cfg.Metas...))
}

return options
}

Expand Down

0 comments on commit 36296fb

Please sign in to comment.