-
Notifications
You must be signed in to change notification settings - Fork 3
/
default.go
149 lines (127 loc) · 5.07 KB
/
default.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) Tetrate, Inc 2018 All Rights Reserved.
// Copyright 2017 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License 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 log // nolint: golint
import (
"fmt"
"go.uber.org/zap/zapcore"
)
func registerDefaultScope() *Scope {
return RegisterScope(DefaultScopeName, "Unscoped logging messages.", 1)
}
var defaultScope = registerDefaultScope()
// Error outputs a message at error level.
func Error(msg string, fields ...zapcore.Field) {
if defaultScope.GetOutputLevel() >= ErrorLevel {
defaultScope.emit(zapcore.ErrorLevel, defaultScope.GetStackTraceLevel() >= ErrorLevel, msg, fields)
}
}
// Errora uses fmt.Sprint to construct and log a message at error level.
func Errora(args ...interface{}) {
if defaultScope.GetOutputLevel() >= ErrorLevel {
defaultScope.emit(zapcore.ErrorLevel, defaultScope.GetStackTraceLevel() >= ErrorLevel, fmt.Sprint(args...), nil)
}
}
// Errorf uses fmt.Sprintf to construct and log a message at error level.
func Errorf(template string, args ...interface{}) {
if defaultScope.GetOutputLevel() >= ErrorLevel {
msg := template
if len(args) > 0 {
msg = fmt.Sprintf(template, args...)
}
defaultScope.emit(zapcore.ErrorLevel, defaultScope.GetStackTraceLevel() >= ErrorLevel, msg, nil)
}
}
// ErrorEnabled returns whether output of messages using this scope is currently enabled for error-level output.
func ErrorEnabled() bool {
return defaultScope.GetOutputLevel() >= ErrorLevel
}
// Warn outputs a message at warn level.
func Warn(msg string, fields ...zapcore.Field) {
if defaultScope.GetOutputLevel() >= WarnLevel {
defaultScope.emit(zapcore.WarnLevel, defaultScope.GetStackTraceLevel() >= WarnLevel, msg, fields)
}
}
// Warna uses fmt.Sprint to construct and log a message at warn level.
func Warna(args ...interface{}) {
if defaultScope.GetOutputLevel() >= WarnLevel {
defaultScope.emit(zapcore.WarnLevel, defaultScope.GetStackTraceLevel() >= WarnLevel, fmt.Sprint(args...), nil)
}
}
// Warnf uses fmt.Sprintf to construct and log a message at warn level.
func Warnf(template string, args ...interface{}) {
if defaultScope.GetOutputLevel() >= WarnLevel {
msg := template
if len(args) > 0 {
msg = fmt.Sprintf(template, args...)
}
defaultScope.emit(zapcore.WarnLevel, defaultScope.GetStackTraceLevel() >= WarnLevel, msg, nil)
}
}
// WarnEnabled returns whether output of messages using this scope is currently enabled for warn-level output.
func WarnEnabled() bool {
return defaultScope.GetOutputLevel() >= WarnLevel
}
// Info outputs a message at info level.
func Info(msg string, fields ...zapcore.Field) {
if defaultScope.GetOutputLevel() >= InfoLevel {
defaultScope.emit(zapcore.InfoLevel, defaultScope.GetStackTraceLevel() >= InfoLevel, msg, fields)
}
}
// Infoa uses fmt.Sprint to construct and log a message at info level.
func Infoa(args ...interface{}) {
if defaultScope.GetOutputLevel() >= InfoLevel {
defaultScope.emit(zapcore.InfoLevel, defaultScope.GetStackTraceLevel() >= InfoLevel, fmt.Sprint(args...), nil)
}
}
// Infof uses fmt.Sprintf to construct and log a message at info level.
func Infof(template string, args ...interface{}) {
if defaultScope.GetOutputLevel() >= InfoLevel {
msg := template
if len(args) > 0 {
msg = fmt.Sprintf(template, args...)
}
defaultScope.emit(zapcore.InfoLevel, defaultScope.GetStackTraceLevel() >= InfoLevel, msg, nil)
}
}
// InfoEnabled returns whether output of messages using this scope is currently enabled for info-level output.
func InfoEnabled() bool {
return defaultScope.GetOutputLevel() >= InfoLevel
}
// Debug outputs a message at debug level.
func Debug(msg string, fields ...zapcore.Field) {
if defaultScope.GetOutputLevel() >= DebugLevel {
defaultScope.emit(zapcore.DebugLevel, defaultScope.GetStackTraceLevel() >= DebugLevel, msg, fields)
}
}
// Debuga uses fmt.Sprint to construct and log a message at debug level.
func Debuga(args ...interface{}) {
if defaultScope.GetOutputLevel() >= DebugLevel {
defaultScope.emit(zapcore.DebugLevel, defaultScope.GetStackTraceLevel() >= DebugLevel, fmt.Sprint(args...), nil)
}
}
// Debugf uses fmt.Sprintf to construct and log a message at debug level.
func Debugf(template string, args ...interface{}) {
if defaultScope.GetOutputLevel() >= DebugLevel {
msg := template
if len(args) > 0 {
msg = fmt.Sprintf(template, args...)
}
defaultScope.emit(zapcore.DebugLevel, defaultScope.GetStackTraceLevel() >= DebugLevel, msg, nil)
}
}
// DebugEnabled returns whether output of messages using this scope is currently enabled for debug-level output.
func DebugEnabled() bool {
return defaultScope.GetOutputLevel() >= DebugLevel
}