forked from op/go-logging
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlevel.go
50 lines (42 loc) · 976 Bytes
/
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
// Copyright 2013, Örjan Persson. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package logging
import (
"errors"
"strings"
)
// ErrInvalidLogLevel is used when an invalid log level has been used.
var ErrInvalidLogLevel = errors.New("logger: invalid log level")
// Level defines all available log levels for log messages.
type Level int
// Log levels.
const (
CRITICAL Level = iota
ERROR
WARNING
NOTICE
INFO
DEBUG
)
var levelNames = []string{
"CRITICAL",
"ERROR",
"WARNING",
"NOTICE",
"INFO",
"DEBUG",
}
// String returns the string representation of a logging level.
func (p Level) String() string {
return levelNames[p]
}
// LogLevel returns the log level from a string representation.
func LogLevel(level string) (Level, error) {
for i, name := range levelNames {
if strings.EqualFold(name, level) {
return Level(i), nil
}
}
return ERROR, ErrInvalidLogLevel
}