-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger.go
38 lines (28 loc) · 1.01 KB
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package internal
import (
"log"
"github.com/Kyagara/equinox/api"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// Creates a new zap.Logger from the configuration parameters provided.
func NewLogger(config *api.EquinoxConfig) *zap.SugaredLogger {
zapConfig := zap.NewProductionConfig()
equinoxOptions := &api.EquinoxConfig{
Retry: config.Retry,
Timeout: config.Timeout,
TTL: config.TTL,
RateLimit: config.RateLimit,
}
zapConfig.Level = zap.NewAtomicLevelAt(zapcore.Level(config.LogLevel))
logger, err := zapConfig.Build(zap.Fields(zap.Object("equinox", equinoxOptions)))
if err != nil {
log.Fatalf("failed to initialize logger: %v", err)
}
return logger.Sugar()
}
// Used to access the logger from the InternalClient, this is used to log events from other clients (RiotClient, LOLClient...)
func (c *InternalClient) Logger(client string, endpoint string, method string) *zap.SugaredLogger {
logger := c.logger.With("client", client, "endpoint", endpoint, "method", method)
return logger
}