Skip to content

Commit

Permalink
Custom logger (#20)
Browse files Browse the repository at this point in the history
* public keys fix

* LogFast has been added as a Fast custom logging function
  • Loading branch information
misnaged authored Feb 12, 2023
1 parent 1f588ce commit 74cf53a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
28 changes: 28 additions & 0 deletions logger/fast_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package logger

import (
"github.com/gateway-fm/scriptorium/fast_helper"
"github.com/gateway-fm/scriptorium/helper"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
)

// LogWithFastContext is invoking Zap Logger function with fasthttp context
func LogWithFastContext(ctx *fasthttp.RequestCtx) *Zaplog {
initLogger()

publicKey := fast_helper.GetPublicKey(ctx)
if publicKey == "" {
publicKey = helper.PublicKeyNotSet
}

return instance.With(
zap.String(string(helper.ContextKeyRequestID), fast_helper.GetRequestID(ctx)),
zap.String(string(helper.PublicKey), publicKey),
)
}

func LogFast(ctx *fasthttp.RequestCtx) *Zaplog {
initLogger()
return instance
}
17 changes: 0 additions & 17 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package logger
import (
"context"
"encoding/json"
"github.com/gateway-fm/scriptorium/fast_helper"
"github.com/valyala/fasthttp"
"sync"

"go.uber.org/zap"
Expand Down Expand Up @@ -71,21 +69,6 @@ func LogWithContext(ctx context.Context) *Zaplog {
)
}

// LogWithFastContext is invoking Zap Logger function with fasthttp context
func LogWithFastContext(ctx *fasthttp.RequestCtx) *Zaplog {
initLogger()

publicKey := fast_helper.GetPublicKey(ctx)
if publicKey == "" {
publicKey = helper.PublicKeyNotSet
}

return instance.With(
zap.String(string(helper.ContextKeyRequestID), fast_helper.GetRequestID(ctx)),
zap.String(string(helper.PublicKey), publicKey),
)
}

func (z *Zaplog) With(fields ...zapcore.Field) *Zaplog {
return &Zaplog{z.Logger.With(fields...), z.redactor}
}
Expand Down

0 comments on commit 74cf53a

Please sign in to comment.