Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to match log 1.9.2 extended level color format #17

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ manual-check:
go run ./levelsDemo 2>&1 | TZ=UTC go run -race .
@echo "=========== Without Timestamp nor go Routine ID: ==========="
go run ./levelsDemo -logger-timestamp=false -logger-goroutine=false 2>&1 | go run -race .
@echo "=========== Without file/line ==========="
go run ./levelsDemo -logger-file-line=false -logger-timestamp=false -logger-goroutine=false 2>&1 | go run -race .
@echo "=========== Without Color: ==========="
go run ./levelsDemo 2>&1 | go run -race . -no-color

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module fortio.org/logc
go 1.18

require (
fortio.org/cli v1.3.0
fortio.org/log v1.9.1
fortio.org/scli v1.10.0
fortio.org/cli v1.3.1
fortio.org/log v1.9.2
fortio.org/scli v1.10.1
)

require (
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
fortio.org/assert v1.1.4 h1:Za1RaG+OjsTMpQS3J3UCvTF6wc4+IOHCz+jAOU37Y4o=
fortio.org/cli v1.3.0 h1:OsM2P/OIjHFa47mUN914v32ZmgQKJdVrvyiKIYQSaVw=
fortio.org/cli v1.3.0/go.mod h1:eg30mF10yx+T9z6fr1ES87KCfmGaebnhnhbqc8t3IBo=
fortio.org/cli v1.3.1 h1:ExJyciUTLLY1gznExrthduDyw0jKKP95UKrMGfh+n+8=
fortio.org/cli v1.3.1/go.mod h1:R4+pCDYD+40fvomN0yg+CZmU6gkA1PrsunR2hy0dfts=
fortio.org/dflag v1.5.2 h1:F9XVRj4Qr2IbJP7BMj7XZc9wB0Q/RZ61Ool+4YPVad8=
fortio.org/dflag v1.5.2/go.mod h1:ppb/A8u+KKg+qUUYZNYuvRnXuVb8IsdHb/XGzsmjkN8=
fortio.org/log v1.9.1 h1:yNxHqTL6g9VdT38g/BehUZkNOuczxnl2YsdTyENn5YM=
fortio.org/log v1.9.1/go.mod h1:u/8/2lyczXq52aT5Nw6reD+3cR6m/EbS2jBiIYhgiTU=
fortio.org/scli v1.10.0 h1:0OGr8g7mcfQ0UXgTODwiw4XoWdOgkbzU+8GIH9Qo4P8=
fortio.org/scli v1.10.0/go.mod h1:T7M7THNaLG58ryqCc7E87dwBPXfraz3k+7HngNlVwWA=
fortio.org/log v1.9.2 h1:rVCzSFhTD+lsdGUhVuTWoqdFjJP+XD3da9p09pwPohY=
fortio.org/log v1.9.2/go.mod h1:u/8/2lyczXq52aT5Nw6reD+3cR6m/EbS2jBiIYhgiTU=
fortio.org/scli v1.10.1 h1:jJVvPcK9RO2OOKc2CzxwLavJsvXxr1DwCU6VH3efCy8=
fortio.org/scli v1.10.1/go.mod h1:A7ASXPbm6DDhtuPZV6pAiNfAwcUchABy41ndZk8AID0=
fortio.org/sets v1.0.3 h1:HzewdGjH69YmyW06yzplL35lGr+X4OcqQt0qS6jbaO4=
fortio.org/sets v1.0.3/go.mod h1:QZVj0r6KP/ZD9ebySW9SgxVNy/NjghUfyHW9NN+WU+4=
fortio.org/version v1.0.2 h1:8NwxdX58aoeKx7T5xAPO0xlUu1Hpk42nRz5s6e6eKZ0=
Expand Down
9 changes: 6 additions & 3 deletions logc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ func LevelToColor(levelStr string) (string, string) {
level, found := log.JSONStringLevelToLevel[levelStr]
if !found {
log.Critf("Bug/Unknown level %q", levelStr)
return "?", log.Colors.Blue
return log.Colors.BrightRed + "?", log.Colors.Blue
}
return log.LevelToStrA[level][0:1], log.LevelToColor[level]
log.Debugf("level %q -> %d", levelStr, level)
return log.ColorLevelToStr(level), log.LevelToColor[level]
}

// GetAttributes returns the remaining/additional attributes after the `msg`, if any, for text output.
Expand Down Expand Up @@ -101,7 +102,9 @@ func ProcessLogLine(w io.Writer, prevDate *time.Time, line []byte) {
fileLine := ""
if e.Line != 0 {
fileLine = fmt.Sprintf("%s:%d> ", e.File, e.Line)
} else {
lvl += ">"
}
// Msg can be multi line.
fmt.Fprintf(w, "%s%s%s %s%s%s%s\n", tsStr, color, lvl, fileLine, e.Msg, GetAttributes(string(line)), log.Colors.Reset)
fmt.Fprintf(w, "%s%s %s%s%s%s%s\n", tsStr, lvl, fileLine, color, e.Msg, GetAttributes(string(line)), log.Colors.Reset)
}
5 changes: 3 additions & 2 deletions logc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func TestLevels(t *testing.T) {
in string
want string
}{
{`{"level":"trace","msg":"foo"}`, log.Colors.Cyan + "V foo" + log.Colors.Reset + "\n"},
{`{"level":"xyz","msg":"foo"}`, log.Colors.Blue + "? foo" + log.Colors.Reset + "\n"},
{`{"level":"trace","msg":"foo"}`, log.Colors.Cyan + "Verb" + log.Colors.DarkGray + "> " +
log.Colors.Cyan + "foo" + log.Colors.Reset + "\n"},
{`{"level":"xyz","msg":"foo"}`, log.Colors.BrightRed + "?> " + log.Colors.Blue + "foo" + log.Colors.Reset + "\n"},
} {
buf := &strings.Builder{}
w := bufio.NewWriter(buf)
Expand Down