| 1 |
package log |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/evilsocket/islazy/tui" |
| 5 |
) |
| 6 |
|
| 7 |
// Verbosity represents the verbosity level of the logger. |
| 8 |
type Verbosity int |
| 9 |
|
| 10 |
const ( |
| 11 |
// Debug messages. |
| 12 |
DEBUG Verbosity = iota |
| 13 |
// Informative messages. |
| 14 |
INFO |
| 15 |
// Informative messages that are important. |
| 16 |
IMPORTANT |
| 17 |
// Warning messages. |
| 18 |
WARNING |
| 19 |
// Recoverable error conditions. |
| 20 |
ERROR |
| 21 |
// Fatal error conditions. |
| 22 |
FATAL |
| 23 |
) |
| 24 |
|
| 25 |
var ( |
| 26 |
// LevelNames is a map of the names ( {level:name} ) of each verbosity level. |
| 27 |
LevelNames = map[Verbosity]string{ |
| 28 |
DEBUG: "dbg", |
| 29 |
INFO: "inf", |
| 30 |
IMPORTANT: "imp", |
| 31 |
WARNING: "war", |
| 32 |
ERROR: "err", |
| 33 |
FATAL: "!!!", |
| 34 |
} |
| 35 |
// LevelColors is a map of the colors ( {level:color} ) of each verbosity level. |
| 36 |
LevelColors = map[Verbosity]string{ |
| 37 |
DEBUG: tui.DIM + tui.FOREBLACK + tui.BACKDARKGRAY, |
| 38 |
INFO: tui.FOREWHITE + tui.BACKGREEN, |
| 39 |
IMPORTANT: tui.FOREWHITE + tui.BACKLIGHTBLUE, |
| 40 |
WARNING: tui.FOREWHITE + tui.BACKYELLOW, |
| 41 |
ERROR: tui.FOREWHITE + tui.BACKRED, |
| 42 |
FATAL: tui.FOREWHITE + tui.BACKRED + tui.BOLD, |
| 43 |
} |
| 44 |
) |
| 45 |
|
| 46 |
// LevelName returns the name of a verbosity level. |
| 47 |
func LevelName(v Verbosity) string { |
| 48 |
return LevelNames[v] |
| 49 |
} |
| 50 |
|
| 51 |
// LevelColor returns the color of a verbosity level or "" if effects are disabled. |
| 52 |
func LevelColor(v Verbosity) string { |
| 53 |
if NoEffects { |
| 54 |
return "" |
| 55 |
} |
| 56 |
return LevelColors[v] |
| 57 |
} |