Skip to content

Commit

Permalink
Print raw string to the outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinguidee committed Dec 10, 2023
1 parent a068f5e commit 17521ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (l *Logger) Request(msg string, fields ...KeyValue) {
l.print(color.FgGreen, LogTagRequest, msg, fields...)
}

func (l *Logger) Raw(msg string) {
for _, output := range *l.outputs {
output.printRaw(msg)
}
}

func (l *Logger) print(color color.Attribute, tag Tag, msg string, fields ...KeyValue) {
for _, output := range *l.outputs {
output.print(&Line{
Expand Down
22 changes: 18 additions & 4 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path"
"strings"
"time"
)

Expand All @@ -17,6 +18,7 @@ const (

type Output interface {
print(line *Line)
printRaw(line string)
open() error
close() error
}
Expand Down Expand Up @@ -72,7 +74,11 @@ type OutputFile struct {
}

func (out *OutputFile) print(l *Line) {
_, _ = fmt.Fprintln(out.file, l.ToFormat(out.format))
out.printRaw(l.ToFormat(out.format))
}

func (out *OutputFile) printRaw(line string) {
_, _ = fmt.Fprintln(out.file, line)
}

func (out *OutputFile) open() error {
Expand All @@ -97,14 +103,18 @@ type OutputStd struct {
}

func (o OutputStd) print(l *Line) {
o.printRaw(l.ToColoredText())
}

func (o OutputStd) printRaw(line string) {
var file *os.File
if l.tag == LogTagError {
if strings.Contains(line, "ERR") {
file = o.stderr
} else {
file = o.stdout
}

_, _ = fmt.Fprintln(file, l.ToColoredText())
_, _ = fmt.Fprintln(file, line)
}

func (o OutputStd) open() error {
Expand All @@ -121,7 +131,11 @@ type OutputFunc struct {
}

func (o *OutputFunc) print(l *Line) {
o.fc(l.ToFormat(o.format))
o.printRaw(l.ToFormat(o.format))
}

func (o *OutputFunc) printRaw(line string) {
o.fc(line)
}

func (o *OutputFunc) open() error {
Expand Down

0 comments on commit 17521ed

Please sign in to comment.