| 1 |
package logging |
| 2 |
|
| 3 |
// A Level represents a logging level. |
| 4 |
type Level uint8 |
| 5 |
|
| 6 |
// The following constants represent logging levels in increasing levels of seriousness. |
| 7 |
const ( |
| 8 |
// LevelDebug are debug output useful during program testing |
| 9 |
// and debugging. |
| 10 |
LevelDebug = 1 << iota |
| 11 |
|
| 12 |
// LevelInfo is used for informational messages. |
| 13 |
LevelInfo |
| 14 |
|
| 15 |
// LevelWarning is for messages that are warning conditions: |
| 16 |
// they're not indicative of a failure, but of a situation |
| 17 |
// that may lead to a failure later. |
| 18 |
LevelWarning |
| 19 |
|
| 20 |
// LevelError is for messages indicating an error of some |
| 21 |
// kind. |
| 22 |
LevelError |
| 23 |
|
| 24 |
// LevelCritical are messages for critical conditions. |
| 25 |
LevelCritical |
| 26 |
|
| 27 |
// LevelFatal messages are akin to syslog's LOG_EMERG: the |
| 28 |
// system is unusable and cannot continue execution. |
| 29 |
LevelFatal |
| 30 |
) |
| 31 |
|
| 32 |
const DefaultLevel = LevelInfo |
| 33 |
|
| 34 |
// Cheap integer to fixed-width decimal ASCII. Give a negative width |
| 35 |
// to avoid zero-padding. (From log/log.go in the standard library). |
| 36 |
func itoa(i int, wid int) string { |
| 37 |
// Assemble decimal in reverse order. |
| 38 |
var b [20]byte |
| 39 |
bp := len(b) - 1 |
| 40 |
for i >= 10 || wid > 1 { |
| 41 |
wid-- |
| 42 |
q := i / 10 |
| 43 |
b[bp] = byte('0' + i - q*10) |
| 44 |
bp-- |
| 45 |
i = q |
| 46 |
} |
| 47 |
// i < 10 |
| 48 |
b[bp] = byte('0' + i) |
| 49 |
return string(b[bp:]) |
| 50 |
} |
| 51 |
|
| 52 |
func writeToOut(level Level) bool { |
| 53 |
if level < LevelWarning { |
| 54 |
return true |
| 55 |
} |
| 56 |
return false |
| 57 |
} |
| 58 |
|
| 59 |
var levelPrefix = [...]string{ |
| 60 |
LevelDebug: "DEBUG", |
| 61 |
LevelInfo: "INFO", |
| 62 |
LevelWarning: "WARNING", |
| 63 |
LevelError: "ERROR", |
| 64 |
LevelCritical: "CRITICAL", |
| 65 |
LevelFatal: "FATAL", |
| 66 |
} |
| 67 |
|
| 68 |
// DateFormat contains the default date format string used by the logger. |
| 69 |
const DateFormat = "2006-01-02T15:03:04-0700" |