-
Notifications
You must be signed in to change notification settings - Fork 883
/
level.go
74 lines (63 loc) · 2.35 KB
/
level.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
// Copyright (C) MongoDB, Inc. 2023-present.
//
// 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
package logger
import "strings"
// DiffToInfo is the number of levels in the Go Driver that come before the
// "Info" level. This should ensure that "Info" is the 0th level passed to the
// sink.
const DiffToInfo = 1
// Level is an enumeration representing the log severity levels supported by
// the driver. The order of the logging levels is important. The driver expects
// that a user will likely use the "logr" package to create a LogSink, which
// defaults InfoLevel as 0. Any additions to the Level enumeration before the
// InfoLevel will need to also update the "diffToInfo" constant.
type Level int
const (
// LevelOff suppresses logging.
LevelOff Level = iota
// LevelInfo enables logging of informational messages. These logs are
// high-level information about normal driver behavior.
LevelInfo
// LevelDebug enables logging of debug messages. These logs can be
// voluminous and are intended for detailed information that may be
// helpful when debugging an application.
LevelDebug
)
const (
levelLiteralOff = "off"
levelLiteralEmergency = "emergency"
levelLiteralAlert = "alert"
levelLiteralCritical = "critical"
levelLiteralError = "error"
levelLiteralWarning = "warning"
levelLiteralNotice = "notice"
levelLiteralInfo = "info"
levelLiteralDebug = "debug"
levelLiteralTrace = "trace"
)
var LevelLiteralMap = map[string]Level{
levelLiteralOff: LevelOff,
levelLiteralEmergency: LevelInfo,
levelLiteralAlert: LevelInfo,
levelLiteralCritical: LevelInfo,
levelLiteralError: LevelInfo,
levelLiteralWarning: LevelInfo,
levelLiteralNotice: LevelInfo,
levelLiteralInfo: LevelInfo,
levelLiteralDebug: LevelDebug,
levelLiteralTrace: LevelDebug,
}
// ParseLevel will check if the given string is a valid environment variable
// for a logging severity level. If it is, then it will return the associated
// driver's Level. The default Level is “LevelOff”.
func ParseLevel(str string) Level {
for literal, level := range LevelLiteralMap {
if strings.EqualFold(literal, str) {
return level
}
}
return LevelOff
}