File: levels.go

package info (click to toggle)
golang-github-kisom-goutils 0.0~git20161101.0.858c9cb-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 384 kB
  • ctags: 331
  • sloc: makefile: 6
file content (69 lines) | stat: -rw-r--r-- 1,638 bytes parent folder | download | duplicates (3)
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
package logging

// A Level represents a logging level.
type Level uint8

// The following constants represent logging levels in increasing levels of seriousness.
const (
	// LevelDebug are debug output useful during program testing
	// and debugging.
	LevelDebug = 1 << iota

	// LevelInfo is used for informational messages.
	LevelInfo

	// LevelWarning is for messages that are warning conditions:
	// they're not indicative of a failure, but of a situation
	// that may lead to a failure later.
	LevelWarning

	// LevelError is for messages indicating an error of some
	// kind.
	LevelError

	// LevelCritical are messages for critical conditions.
	LevelCritical

	// LevelFatal messages are akin to syslog's LOG_EMERG: the
	// system is unusable and cannot continue execution.
	LevelFatal
)

const DefaultLevel = LevelInfo

// Cheap integer to fixed-width decimal ASCII.  Give a negative width
// to avoid zero-padding. (From log/log.go in the standard library).
func itoa(i int, wid int) string {
	// Assemble decimal in reverse order.
	var b [20]byte
	bp := len(b) - 1
	for i >= 10 || wid > 1 {
		wid--
		q := i / 10
		b[bp] = byte('0' + i - q*10)
		bp--
		i = q
	}
	// i < 10
	b[bp] = byte('0' + i)
	return string(b[bp:])
}

func writeToOut(level Level) bool {
	if level < LevelWarning {
		return true
	}
	return false
}

var levelPrefix = [...]string{
	LevelDebug:    "DEBUG",
	LevelInfo:     "INFO",
	LevelWarning:  "WARNING",
	LevelError:    "ERROR",
	LevelCritical: "CRITICAL",
	LevelFatal:    "FATAL",
}

// DateFormat contains the default date format string used by the logger.
const DateFormat = "2006-01-02T15:03:04-0700"