-
Notifications
You must be signed in to change notification settings - Fork 720
/
logger.go
63 lines (47 loc) · 1.68 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
// Package logger is the CNI Logger interface, using zap
package logger
//Log is global variable so that log functions can be directly accessed
var log Logger
//Fields Type to pass when we want to call WithFields for structured logging
type Fields map[string]interface{}
//Logger is our contract for the logger
type Logger interface {
Debugf(format string, args ...interface{})
Debug(format string)
Infof(format string, args ...interface{})
Info(format string)
Warnf(format string, args ...interface{})
Warn(format string)
Errorf(format string, args ...interface{})
Error(format string)
Fatalf(format string, args ...interface{})
Panicf(format string, args ...interface{})
WithFields(keyValues Fields) Logger
}
// Get returns an default instance of the zap logger
func Get() Logger {
if log == nil {
logConfig := LoadLogConfig()
log = New(logConfig)
log.Info("Initialized new logger as an existing instance was not found")
}
return log
}
//New logger initializes logger
func New(inputLogConfig *Configuration) Logger {
log = inputLogConfig.newZapLogger()
log.Info("Constructed new logger instance")
return log
}