Skip to content

Commit

Permalink
logger: adjustment for the new Done function - use nil instead of emp…
Browse files Browse the repository at this point in the history
…ty func
  • Loading branch information
ReneWerner87 committed Nov 18, 2022
1 parent e8f8cb6 commit 3d39b82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions middleware/logger/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Config struct {
// Done is a function that is called after the log string for a request is written to Output,
// and pass the log string as parameter.
//
// Optional. Default: a function that does nothing.
// Optional. Default: nil
Done func(c *fiber.Ctx, logString []byte)

// tagFunctions defines the custom tag action
Expand Down Expand Up @@ -69,7 +69,7 @@ type LogFunc func(buf *bytebufferpool.ByteBuffer, c *fiber.Ctx, data *Data, extr
// ConfigDefault is the default config
var ConfigDefault = Config{
Next: nil,
Done: func(c *fiber.Ctx, logString []byte) {},
Done: nil,
Format: "[${time}] ${status} - ${latency} ${method} ${path}\n",
TimeFormat: "15:04:05",
TimeZone: "Local",
Expand Down
8 changes: 6 additions & 2 deletions middleware/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ func New(config ...Config) fiber.Handler {
// Write buffer to output
_, _ = cfg.Output.Write(buf.Bytes())

cfg.Done(c, buf.Bytes())
if cfg.Done != nil {
cfg.Done(c, buf.Bytes())
}

// Put buffer back to pool
bytebufferpool.Put(buf)
Expand Down Expand Up @@ -194,7 +196,9 @@ func New(config ...Config) fiber.Handler {
}
mu.Unlock()

cfg.Done(c, buf.Bytes())
if cfg.Done != nil {
cfg.Done(c, buf.Bytes())
}

// Put buffer back to pool
bytebufferpool.Put(buf)
Expand Down

0 comments on commit 3d39b82

Please sign in to comment.