Skip to content

Commit

Permalink
errco: fixed log layout
Browse files Browse the repository at this point in the history
  • Loading branch information
gekigek99 committed Feb 13, 2023
1 parent 1e29729 commit d444a47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
46 changes: 23 additions & 23 deletions lib/errco/errco.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,37 +106,37 @@ func (logMsh *MshLog) Log(tracing bool) *MshLog {
logMod.Mex = COLOR_CYAN + logMod.Mex + COLOR_RESET
}

var t string
// set logMod colors depending on logMod type
// set type, origin, code
var typ, ori, cod string
switch logMod.Typ {
case TYPE_INF:
t = COLOR_BLUE + string(logMod.Typ) + COLOR_RESET
typ = fmt.Sprintf("%s%-6s%s", COLOR_BLUE, string(logMod.Typ), COLOR_RESET)
ori = "\x00"
cod = "\x00"
case TYPE_SER:
t = COLOR_GRAY + string(logMod.Typ) + COLOR_RESET
logMod.Mex = COLOR_GRAY + logMod.Mex + "\x00" + COLOR_RESET
typ = fmt.Sprintf("%s%-6s%s", COLOR_GRAY, string(logMod.Typ), COLOR_RESET)
ori = "\x00"
cod = "\x00"
case TYPE_BYT:
t = COLOR_PURPLE + string(logMod.Typ) + COLOR_RESET
typ = fmt.Sprintf("%s%-6s%s", COLOR_PURPLE, string(logMod.Typ), COLOR_RESET)
ori = "\x00"
cod = "\x00"
case TYPE_WAR:
t = COLOR_YELLOW + string(logMod.Typ) + COLOR_RESET
typ = fmt.Sprintf("%s%-6s%s", COLOR_YELLOW, string(logMod.Typ), COLOR_RESET)
ori = fmt.Sprintf("%s%s:%s ", COLOR_YELLOW, logMod.Ori, COLOR_RESET)
cod = fmt.Sprintf(" [%06x]", logMod.Cod)
case TYPE_ERR:
t = COLOR_RED + string(logMod.Typ) + COLOR_RESET
typ = fmt.Sprintf("%s%-6s%s", COLOR_RED, string(logMod.Typ), COLOR_RESET)
ori = fmt.Sprintf("%s%s:%s ", COLOR_YELLOW, logMod.Ori, COLOR_RESET)
cod = fmt.Sprintf(" [%06x]", logMod.Cod)
}

// print logMod depending on logMod type
switch logMod.Typ {
case TYPE_INF, TYPE_SER, TYPE_BYT:
log.Printf("[%-14s %-4s] %s\n",
t,
strings.Repeat("≡", 4-int(logMod.Lvl)),
fmt.Sprintf(logMod.Mex, logMod.Arg...))
case TYPE_WAR, TYPE_ERR:
log.Printf("[%-14s %-4s] %s %s %s\n",
t,
strings.Repeat("≡", 4-int(logMod.Lvl)),
LogOri(COLOR_YELLOW)+logMod.Ori+":"+LogOri(COLOR_RESET),
fmt.Sprintf(logMod.Mex, logMod.Arg...),
fmt.Sprintf("[%06x]", logMod.Cod))
}
log.Printf("[%s%-4s] %s%s%s\n",
typ,
strings.Repeat("≡", 4-int(logMod.Lvl)),
ori,
fmt.Sprintf(logMod.Mex, logMod.Arg...),
cod)

// return original log
return logMsh
Expand Down
4 changes: 2 additions & 2 deletions lib/servctrl/servctrl-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func printerOutErr() {
for scanner.Scan() {
line = scanner.Text()

errco.NewLogln(errco.TYPE_SER, errco.LVL_2, errco.ERROR_NIL, line)
errco.NewLogln(errco.TYPE_SER, errco.LVL_2, errco.ERROR_NIL, errco.COLOR_GRAY+line+errco.COLOR_RESET)

// communicate to lastOut so that func Execute() can return the output of the command.
// must be a non-blocking select or it might cause hanging
Expand Down Expand Up @@ -312,7 +312,7 @@ func printerOutErr() {
for scanner.Scan() {
line = scanner.Text()

errco.NewLogln(errco.TYPE_SER, errco.LVL_2, errco.ERROR_NIL, line)
errco.NewLogln(errco.TYPE_SER, errco.LVL_2, errco.ERROR_NIL, errco.COLOR_GRAY+line+errco.COLOR_RESET)
}
}()
}
Expand Down

0 comments on commit d444a47

Please sign in to comment.