Skip to content

Commit

Permalink
🚀 Consistent way of logging and fix middleware log format (#2432)
Browse files Browse the repository at this point in the history
* 🚀 Replace fmt.Print* with log.Print* (#2402)

* 🚀 Fix middleware logging format (#2402)
  • Loading branch information
kousikmitra committed May 1, 2023
1 parent 9d8eba5 commit a59d9ba
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions internal/template/html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"html/template"
"io"
"log"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -112,7 +113,7 @@ func (e *Engine) Debug(enabled bool) *Engine {

// Parse is deprecated, please use Load() instead
func (e *Engine) Parse() error {
fmt.Println("Parse() is deprecated, please use Load() instead.")
log.Println("[Warning] Parse() is deprecated, please use Load() instead.")
return e.Load()
}

Expand Down Expand Up @@ -169,7 +170,7 @@ func (e *Engine) Load() error {
}
// Debugging
if e.debug {
fmt.Printf("views: parsed template: %s\n", name)
log.Printf("views: parsed template: %s\n", name)
}
return err
}
Expand Down
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] Store is deprecated, please use Storage\n")
log.Printf("[CACHE] - [Warning] Store is deprecated, please use Storage\n")
cfg.Storage = cfg.Store
}
if cfg.Key != nil {
log.Printf("[CACHE] Key is deprecated, please use KeyGenerator\n")
log.Printf("[CACHE] - [Warning] Key is deprecated, please use KeyGenerator\n")
cfg.KeyGenerator = cfg.Key
}
if cfg.Next == nil {
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] TokenLookup is deprecated, please use KeyLookup\n")
log.Printf("[CSRF] - [Warning] TokenLookup is deprecated, please use KeyLookup\n")
cfg.KeyLookup = cfg.TokenLookup
}
if int(cfg.CookieExpires.Seconds()) > 0 {
log.Printf("[CSRF] CookieExpires is deprecated, please use Expiration\n")
log.Printf("[CSRF] - [Warning] CookieExpires is deprecated, please use Expiration\n")
cfg.Expiration = cfg.CookieExpires
}
if cfg.Cookie != nil {
log.Printf("[CSRF] Cookie is deprecated, please use Cookie* related fields\n")
log.Printf("[CSRF] - [Warning] 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("middleware/idempotency: failed to unlock key %q: %v", key, err)
log.Printf("[IDEMPOTENCY] - [Error] 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] Duration is deprecated, please use Expiration\n")
log.Printf("[LIMITER] - [Warning] Duration is deprecated, please use Expiration\n")
cfg.Expiration = cfg.Duration
}
if cfg.Key != nil {
log.Printf("[LIMITER] Key is deprecated, please us KeyGenerator\n")
log.Printf("[LIMITER] - [Warning] Key is deprecated, please us KeyGenerator\n")
cfg.KeyGenerator = cfg.Key
}
if cfg.Store != nil {
log.Printf("[LIMITER] Store is deprecated, please use Storage\n")
log.Printf("[LIMITER] - [Warning] 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.New is deprecated, please use proxy.Balancer instead\n")
log.Printf("[PROXY] - [Warning] 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] CookieName is deprecated, please use KeyLookup\n")
log.Printf("[SESSION] - [Warning] 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("[Warning] timeout contains data race issues, not ready for production!")
log.Printf("[TIMEOUT] - [Warning] 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("[Warning] recover error %v", err)
log.Printf("[TIMEOUT] - [Warning] recover error %v", err)
}
}()
if err := handler(ctx); err != nil {
log.Printf("[Warning] handler error %v", err)
log.Printf("[TIMEOUT] - [Warning] handler error %v", err)
}
ch <- struct{}{}
}()
Expand Down

0 comments on commit a59d9ba

Please sign in to comment.