refact: refactored core constants into swag.go

This commit is contained in:
evilsocket 2018-01-11 12:19:36 +01:00
commit 2cda9c8c67
5 changed files with 49 additions and 61 deletions

View file

@ -5,50 +5,8 @@ import (
"os"
"sync"
"time"
)
const (
DEBUG = iota
INFO
IMPORTANT
WARNING
ERROR
FATAL
)
const (
BOLD = "\033[1m"
DIM = "\033[2m"
FG_BLACK = "\033[30m"
FG_WHITE = "\033[97m"
BG_DGRAY = "\033[100m"
BG_RED = "\033[41m"
BG_GREEN = "\033[42m"
BG_YELLOW = "\033[43m"
BG_LBLUE = "\033[104m"
RESET = "\033[0m"
)
var (
labels = map[int]string{
DEBUG: "dbg",
INFO: "inf",
IMPORTANT: "imp",
WARNING: "war",
ERROR: "err",
FATAL: "!!!",
}
colors = map[int]string{
DEBUG: DIM + FG_BLACK + BG_DGRAY,
INFO: FG_WHITE + BG_GREEN,
IMPORTANT: FG_WHITE + BG_LBLUE,
WARNING: FG_WHITE + BG_YELLOW,
ERROR: FG_WHITE + BG_RED,
FATAL: FG_WHITE + BG_RED + BOLD,
}
"github.com/evilsocket/bettercap-ng/core"
)
type Event struct {
@ -72,9 +30,9 @@ func NewEvent(tag string, data interface{}) Event {
func (e Event) Label() string {
log := e.Data.(LogMessage)
label := labels[log.Level]
color := colors[log.Level]
return color + label + RESET
label := core.LogLabels[log.Level]
color := core.LogColors[log.Level]
return color + label + core.RESET
}
type EventPool struct {
@ -105,9 +63,9 @@ func (p *EventPool) Add(tag string, data interface{}) {
}
func (p *EventPool) Log(level int, format string, args ...interface{}) {
if level == DEBUG && p.debug == false {
if level == core.DEBUG && p.debug == false {
return
} else if level < ERROR && p.silent == true {
} else if level < core.ERROR && p.silent == true {
return
}
@ -118,7 +76,7 @@ func (p *EventPool) Log(level int, format string, args ...interface{}) {
message,
})
if level == FATAL {
if level == core.FATAL {
fmt.Fprintf(os.Stderr, "%s\n", message)
os.Exit(1)
}