mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -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
|
||||
)
|
||||
|
||||
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 {
|
||||
Tag string `json:"tag"`
|
||||
Time time.Time `json:"time"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type LogMessage struct {
|
||||
Level int
|
||||
Message string
|
||||
}
|
||||
|
||||
func NewEvent(tag string, data interface{}) Event {
|
||||
return Event{
|
||||
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 {
|
||||
NewEvents chan Event
|
||||
debug bool
|
||||
|
@ -68,10 +115,7 @@ func (p *EventPool) Log(level int, format string, args ...interface{}) {
|
|||
return
|
||||
}
|
||||
|
||||
p.Add("sys.log", struct {
|
||||
Level int
|
||||
Message string
|
||||
}{
|
||||
p.Add("sys.log", LogMessage{
|
||||
level,
|
||||
fmt.Sprintf(format, args...),
|
||||
})
|
||||
|
|
|
@ -61,7 +61,13 @@ func (s *EventsStream) Start() error {
|
|||
var e session.Event
|
||||
select {
|
||||
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
|
||||
|
||||
case <-s.quit:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue