mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 04:59:25 -07:00
fix: different stream style for logs
This commit is contained in:
parent
47e814c9a9
commit
e7687c658f
2 changed files with 55 additions and 5 deletions
|
@ -16,12 +16,52 @@ const (
|
||||||
FATAL
|
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,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
Data interface{} `json:"data"`
|
Data interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LogMessage struct {
|
||||||
|
Level int
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
func NewEvent(tag string, data interface{}) Event {
|
func NewEvent(tag string, data interface{}) Event {
|
||||||
return Event{
|
return Event{
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
|
@ -30,6 +70,13 @@ 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
|
||||||
|
}
|
||||||
|
|
||||||
type EventPool struct {
|
type EventPool struct {
|
||||||
NewEvents chan Event
|
NewEvents chan Event
|
||||||
debug bool
|
debug bool
|
||||||
|
@ -68,10 +115,7 @@ func (p *EventPool) Log(level int, format string, args ...interface{}) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Add("sys.log", struct {
|
p.Add("sys.log", LogMessage{
|
||||||
Level int
|
|
||||||
Message string
|
|
||||||
}{
|
|
||||||
level,
|
level,
|
||||||
fmt.Sprintf(format, args...),
|
fmt.Sprintf(format, args...),
|
||||||
})
|
})
|
||||||
|
|
|
@ -61,7 +61,13 @@ func (s *EventsStream) Start() error {
|
||||||
var e session.Event
|
var e session.Event
|
||||||
select {
|
select {
|
||||||
case e = <-s.Session.Events.NewEvents:
|
case e = <-s.Session.Events.NewEvents:
|
||||||
fmt.Printf("[%s] [%s] %v\n", e.Time.Format("2006-01-02 15:04:05"), core.Green(e.Tag), e.Data)
|
tm := e.Time.Format("2006-01-02 15:04:05")
|
||||||
|
|
||||||
|
if e.Tag == "sys.log" {
|
||||||
|
fmt.Printf("[%s] %s %v\n", tm, e.Label(), e.Data.(session.LogMessage).Message)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("[%s] [%s] %v\n", tm, core.Green(e.Tag), e.Data)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
case <-s.quit:
|
case <-s.quit:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue