Skip to content

Commit

Permalink
[log] Add color tag validation
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 19, 2023
1 parent 5a41b18 commit 10af1af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* `[fmtutil/panel]` Added `TOP_LINE` option
* `[fmtutil/panel]` Added `DefaultOptions` variable to set default options for all panels
* `[strutil]` Added method `LenVisual`
* `[log]` Added color tag validation
* `[progress]` Added settings validation
* `[spinner]` Added color tag validation
* `[usage]` Added color tag validation
Expand Down
7 changes: 5 additions & 2 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/strutil"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -337,9 +338,11 @@ func (l *Logger) Print(level uint8, f string, a ...any) error {

switch {
case l.UseColors && showPrefix:
_, err = fmt.Fprintf(w, fmtc.Render("{s-}%s{!} "+Colors[level]+"%s %s{!}"), getTime(), PrefixMap[level], fmt.Sprintf(f, a...))
color := strutil.B(fmtc.IsTag(Colors[level]), Colors[level], "")
_, err = fmt.Fprintf(w, fmtc.Render("{s-}%s{!} "+color+"%s %s{!}"), getTime(), PrefixMap[level], fmt.Sprintf(f, a...))
case l.UseColors && !showPrefix:
_, err = fmt.Fprintf(w, fmtc.Render("{s-}%s{!} "+Colors[level]+"%s{!}"), getTime(), fmt.Sprintf(f, a...))
color := strutil.B(fmtc.IsTag(Colors[level]), Colors[level], "")
_, err = fmt.Fprintf(w, fmtc.Render("{s-}%s{!} "+color+"%s{!}"), getTime(), fmt.Sprintf(f, a...))
case !l.UseColors && showPrefix:
_, err = fmt.Fprintf(w, "%s %s %s", getTime(), PrefixMap[level], fmt.Sprintf(f, a...))
case !l.UseColors && !showPrefix:
Expand Down

0 comments on commit 10af1af

Please sign in to comment.