Skip to content

Commit

Permalink
调整生产选项,去除 pid 的输出
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Dec 27, 2023
1 parent b160fdd commit 783825f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## ✒ 历史版本的特性介绍 (Features in old versions)

### v1.5.8-alpha

> 此版本发布于 2023-12-27
* 调整生产选项,去除 pid 的输出

### v1.5.7-alpha

> 此版本发布于 2023-12-22
Expand Down
10 changes: 6 additions & 4 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Logger struct {
closer io.Closer

withSource bool
withPID bool
}

// NewLogger creates a logger with given options or panics if failed.
Expand Down Expand Up @@ -82,10 +83,7 @@ func NewLoggerGracefully(opts ...Option) (*Logger, error) {
syncer: syncer,
closer: closer,
withSource: conf.withSource,
}

if conf.withPID {
logger = logger.With(keyPID, pid)
withPID: conf.withPID,
}

if conf.syncTimer > 0 {
Expand Down Expand Up @@ -215,6 +213,10 @@ func (l *Logger) newRecord(level slog.Level, msg string, args []any) slog.Record
now := defaults.CurrentTime()
record := slog.NewRecord(now, level, msg, pc)

if l.withPID {
record.AddAttrs(slog.Int(keyPID, pid))
}

var attr slog.Attr
for len(args) > 0 {
attr, args = l.squeezeAttr(args)
Expand Down
2 changes: 1 addition & 1 deletion option.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func WithSyncTimer(d time.Duration) Option {
// We recommend you to use them, so we provide this convenient way to create such a logger.
func ProductionOptions() []Option {
opts := []Option{
WithInfoLevel(), WithPID(), WithRotateFile("./logit.log"),
WithInfoLevel(), WithRotateFile("./logit.log"),
}

return opts
Expand Down

0 comments on commit 783825f

Please sign in to comment.