-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.go
53 lines (44 loc) · 1.39 KB
/
logging.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
package sqldb
import (
"errors"
"log"
)
/*
This file specifically deals with logging for this package. See the config
LoggingLevel field.
*/
// Logging levels, each higher level is inclusive of lower levels; i.e.: if you choose
// to use LogLevelDebug, all Error and Info logging will also be output.
type logLevel int
const (
LogLevelNone logLevel = iota //no logging, really should never be used.
LogLevelError //general errors, most typical use.
LogLevelInfo //some info on db connections, deployment, updates.
LogLevelDebug //primarily used during development.
LogLevelDefault = LogLevelError
)
var (
//ErrInvalidLoggingLevel is returned when an invalid logging level is provided.
ErrInvalidLoggingLevel = errors.New("sqldb: invalid logging level")
)
// errorLn performs log.Println if LoggingLevel is set to LogLevelError or a
// higher logging level.
func (c *Config) errorLn(v ...any) {
if c.LoggingLevel >= LogLevelError {
log.Println(v...)
}
}
// infoLn performs log.Println if LoggingLevel is set to LogLevelInfo or a
// higher logging level.
func (c *Config) infoLn(v ...any) {
if c.LoggingLevel >= LogLevelInfo {
log.Println(v...)
}
}
// debugLn performs log.Println if LoggingLevel is set to LogLevelDebug or a
// higher logging level.
func (c *Config) debugLn(v ...any) {
if c.LoggingLevel >= LogLevelDebug {
log.Println(v...)
}
}