Skip to content

Commit

Permalink
Introducing option to disable log coloring
Browse files Browse the repository at this point in the history
NSM issue: #1594

Signed-off-by: Botond Szirtes <botond.szirtes@est.tech>
  • Loading branch information
bszirtes committed Mar 14, 2024
1 parent b1a3e26 commit 34f2ed5
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pkg/tools/log/logruslogger/formatter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2024 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -33,6 +33,7 @@ type formatter struct {
func newFormatter() *formatter {
f := formatter{}
f.nf.FieldsOrder = []string{"id", "name"}
f.nf.NoColors = true
return &f
}

Expand All @@ -52,11 +53,8 @@ func (f *formatter) Format(entry *logrus.Entry) ([]byte, error) {
// output buffer
bb := &bytes.Buffer{}

split := strings.SplitN(bytesString, "\x1b[0m", 2)
prefix := split[0] + "\x1b[0m"
split[1] = split[1][:len(split[1])-1] // remove trailing \n
bb.WriteString(prefix)
for _, line := range strings.Split(split[1], "\n") {
bytesString = bytesString[:len(bytesString)-1] // remove trailing \n
for _, line := range strings.Split(bytesString, "\n") {
bb.WriteString(line)
bb.WriteString(";\t")
}
Expand Down

0 comments on commit 34f2ed5

Please sign in to comment.