Skip to content

Commit

Permalink
🚀 Consistent way of logging and fix middleware log format #2432 (#2444)
Browse files Browse the repository at this point in the history
- change log patter
  • Loading branch information
ReneWerner87 committed May 1, 2023
1 parent a59d9ba commit 3a7dbd0
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions middleware/cache/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func configDefault(config ...Config) Config {

// Set default values
if cfg.Store != nil {
log.Printf("[CACHE] - [Warning] Store is deprecated, please use Storage\n")
log.Printf("[Warning] - [CACHE] Store is deprecated, please use Storage\n")
cfg.Storage = cfg.Store
}
if cfg.Key != nil {
log.Printf("[CACHE] - [Warning] Key is deprecated, please use KeyGenerator\n")
log.Printf("[Warning] - [CACHE] Key is deprecated, please use KeyGenerator\n")
cfg.KeyGenerator = cfg.Key
}
if cfg.Next == nil {
Expand Down
2 changes: 1 addition & 1 deletion middleware/cors/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func New(config ...Config) fiber.Handler {

// Warning logs if both AllowOrigins and AllowOriginsFunc are set
if cfg.AllowOrigins != ConfigDefault.AllowOrigins && cfg.AllowOriginsFunc != nil {
log.Printf("[CORS] - [Warning] Both 'AllowOrigins' and 'AllowOriginsFunc' have been defined.\n")
log.Printf("[Warning] - [CORS] Both 'AllowOrigins' and 'AllowOriginsFunc' have been defined.\n")
}

// Convert string to slice
Expand Down
6 changes: 3 additions & 3 deletions middleware/csrf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ func configDefault(config ...Config) Config {

// Set default values
if cfg.TokenLookup != "" {
log.Printf("[CSRF] - [Warning] TokenLookup is deprecated, please use KeyLookup\n")
log.Printf("[Warning] - [CSRF] TokenLookup is deprecated, please use KeyLookup\n")
cfg.KeyLookup = cfg.TokenLookup
}
if int(cfg.CookieExpires.Seconds()) > 0 {
log.Printf("[CSRF] - [Warning] CookieExpires is deprecated, please use Expiration\n")
log.Printf("[Warning] - [CSRF] CookieExpires is deprecated, please use Expiration\n")
cfg.Expiration = cfg.CookieExpires
}
if cfg.Cookie != nil {
log.Printf("[CSRF] - [Warning] Cookie is deprecated, please use Cookie* related fields\n")
log.Printf("[Warning] - [CSRF] Cookie is deprecated, please use Cookie* related fields\n")
if cfg.Cookie.Name != "" {
cfg.CookieName = cfg.Cookie.Name
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/idempotency/idempotency.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func New(config ...Config) fiber.Handler {
}
defer func() {
if err := cfg.Lock.Unlock(key); err != nil {
log.Printf("[IDEMPOTENCY] - [Error] failed to unlock key %q: %v", key, err)
log.Printf("[Error] - [IDEMPOTENCY] failed to unlock key %q: %v", key, err)
}
}()

Expand Down
6 changes: 3 additions & 3 deletions middleware/limiter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ func configDefault(config ...Config) Config {

// Set default values
if int(cfg.Duration.Seconds()) > 0 {
log.Printf("[LIMITER] - [Warning] Duration is deprecated, please use Expiration\n")
log.Printf("[Warning] - [LIMITER] Duration is deprecated, please use Expiration\n")
cfg.Expiration = cfg.Duration
}
if cfg.Key != nil {
log.Printf("[LIMITER] - [Warning] Key is deprecated, please us KeyGenerator\n")
log.Printf("[Warning] - [LIMITER] Key is deprecated, please us KeyGenerator\n")
cfg.KeyGenerator = cfg.Key
}
if cfg.Store != nil {
log.Printf("[LIMITER] - [Warning] Store is deprecated, please use Storage\n")
log.Printf("[Warning] - [LIMITER] Store is deprecated, please use Storage\n")
cfg.Storage = cfg.Store
}
if cfg.Next == nil {
Expand Down
2 changes: 1 addition & 1 deletion middleware/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// New is deprecated
func New(config Config) fiber.Handler {
log.Printf("[PROXY] - [Warning] proxy.New is deprecated, please use proxy.Balancer instead\n")
log.Printf("[Warning] - [PROXY] proxy.New is deprecated, please use proxy.Balancer instead\n")
return Balancer(config)
}

Expand Down
2 changes: 1 addition & 1 deletion middleware/session/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func configDefault(config ...Config) Config {
cfg.Expiration = ConfigDefault.Expiration
}
if cfg.CookieName != "" {
log.Printf("[SESSION] - [Warning] CookieName is deprecated, please use KeyLookup\n")
log.Printf("[Warning] - [SESSION] CookieName is deprecated, please use KeyLookup\n")
cfg.KeyLookup = fmt.Sprintf("cookie:%s", cfg.CookieName)
}
if cfg.KeyLookup == "" {
Expand Down
6 changes: 3 additions & 3 deletions middleware/timeout/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var once sync.Once
// Find documentation and sample usage on https://docs.gofiber.io/api/middleware/timeout
func New(handler fiber.Handler, timeout time.Duration) fiber.Handler {
once.Do(func() {
log.Printf("[TIMEOUT] - [Warning] timeout contains data race issues, not ready for production!")
log.Printf("[Warning] - [TIMEOUT] timeout contains data race issues, not ready for production!")
})

if timeout <= 0 {
Expand All @@ -32,11 +32,11 @@ func New(handler fiber.Handler, timeout time.Duration) fiber.Handler {
go func() {
defer func() {
if err := recover(); err != nil {
log.Printf("[TIMEOUT] - [Warning] recover error %v", err)
log.Printf("[Warning] - [TIMEOUT] recover error %v", err)
}
}()
if err := handler(ctx); err != nil {
log.Printf("[TIMEOUT] - [Warning] handler error %v", err)
log.Printf("[Warning] - [TIMEOUT] handler error %v", err)
}
ch <- struct{}{}
}()
Expand Down

0 comments on commit 3a7dbd0

Please sign in to comment.