Debian Codegraph @

debian/vendor/github.com/pingcap/log/global.go

raw
1 // Copyright 2019 PingCAP, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package log
15
16 import (
17 "go.uber.org/zap"
18 "go.uber.org/zap/zapcore"
19 )
20
21 // Debug logs a message at DebugLevel. The message includes any fields passed
22 // at the log site, as well as any fields accumulated on the logger.
23 func Debug(msg string, fields ...zap.Field) {
24 L().WithOptions(zap.AddCallerSkip(1)).Debug(msg, fields...)
25 }
26
27 // Info logs a message at InfoLevel. The message includes any fields passed
28 // at the log site, as well as any fields accumulated on the logger.
29 func Info(msg string, fields ...zap.Field) {
30 L().WithOptions(zap.AddCallerSkip(1)).Info(msg, fields...)
31 }
32
33 // Warn logs a message at WarnLevel. The message includes any fields passed
34 // at the log site, as well as any fields accumulated on the logger.
35 func Warn(msg string, fields ...zap.Field) {
36 L().WithOptions(zap.AddCallerSkip(1)).Warn(msg, fields...)
37 }
38
39 // Error logs a message at ErrorLevel. The message includes any fields passed
40 // at the log site, as well as any fields accumulated on the logger.
41 func Error(msg string, fields ...zap.Field) {
42 L().WithOptions(zap.AddCallerSkip(1)).Error(msg, fields...)
43 }
44
45 // Panic logs a message at PanicLevel. The message includes any fields passed
46 // at the log site, as well as any fields accumulated on the logger.
47 //
48 // The logger then panics, even if logging at PanicLevel is disabled.
49 func Panic(msg string, fields ...zap.Field) {
50 L().WithOptions(zap.AddCallerSkip(1)).Panic(msg, fields...)
51 }
52
53 // Fatal logs a message at FatalLevel. The message includes any fields passed
54 // at the log site, as well as any fields accumulated on the logger.
55 //
56 // The logger then calls os.Exit(1), even if logging at FatalLevel is
57 // disabled.
58 func Fatal(msg string, fields ...zap.Field) {
59 L().WithOptions(zap.AddCallerSkip(1)).Fatal(msg, fields...)
60 }
61
62 // SetLevel alters the logging level.
63 func SetLevel(l zapcore.Level) {
64 _globalP.Level.SetLevel(l)
65 }
66
67 // GetLevel gets the logging level.
68 func GetLevel() zapcore.Level {
69 return _globalP.Level.Level()
70 }