MCPcopy
hub / github.com/dgraph-io/dgraph / InitLogger

Function InitLogger

x/logger.go:28–69  ·  view source on GitHub ↗
(conf *LoggerConf, filename string)

Source from the content-addressed store, hash-verified

26}
27
28func InitLogger(conf *LoggerConf, filename string) (*Logger, error) {
29 config := zap.NewProductionEncoderConfig()
30 config.MessageKey = conf.MessageKey
31 config.LevelKey = zapcore.OmitKey
32 config.EncodeTime = zapcore.ISO8601TimeEncoder
33 // if stdout, then init the logger and return
34 if conf.Output == "stdout" {
35 return &Logger{
36 logger: zap.New(zapcore.NewCore(zapcore.NewJSONEncoder(config),
37 zapcore.AddSync(os.Stdout), zapcore.DebugLevel)),
38 writer: nil,
39 }, nil
40 }
41
42 if err := os.MkdirAll(conf.Output, 0700); err != nil {
43 return nil, err
44 }
45 if conf.EncryptionKey != nil {
46 filename = filename + ".enc"
47 }
48
49 path, err := filepath.Abs(filepath.Join(conf.Output, filename))
50 if err != nil {
51 return nil, err
52 }
53 w := &LogWriter{
54 FilePath: path,
55 MaxSize: conf.Size,
56 MaxAge: conf.Days,
57 EncryptionKey: conf.EncryptionKey,
58 Compress: conf.Compress,
59 }
60 if w, err = w.Init(); err != nil {
61 return nil, err
62 }
63
64 return &Logger{
65 logger: zap.New(zapcore.NewCore(zapcore.NewJSONEncoder(config),
66 zapcore.AddSync(w), zap.DebugLevel)),
67 writer: w,
68 }, nil
69}
70
71type Logger struct {
72 logger *zap.Logger

Callers 1

InitAuditorFunction · 0.92

Calls 1

InitMethod · 0.95

Tested by

no test coverage detected