diff options
| author | Paul Buetow <paul@buetow.org> | 2021-11-02 08:11:40 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-11-02 08:11:40 +0200 |
| commit | 1ec88deea93047a9d1a366e032b2a54aa3cd362b (patch) | |
| tree | 465f30673aa097a2b369e7c3d2032b041ff4f8e6 /internal/io/dlog/loggers/file.go | |
| parent | 2e9ce81c47d45dd1f2c607df6e19bdfdc3bb3cc8 (diff) | |
Bugfix: Dealing correctly with files without newline characters, also add more tests
Diffstat (limited to 'internal/io/dlog/loggers/file.go')
| -rw-r--r-- | internal/io/dlog/loggers/file.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/internal/io/dlog/loggers/file.go b/internal/io/dlog/loggers/file.go index 94824fe..9dce251 100644 --- a/internal/io/dlog/loggers/file.go +++ b/internal/io/dlog/loggers/file.go @@ -17,6 +17,7 @@ type fileWriter struct{} type fileMessageBuf struct { now time.Time message string + nl bool } type file struct { @@ -86,10 +87,18 @@ func (f *file) Start(ctx context.Context, wg *sync.WaitGroup) { } func (f *file) Log(now time.Time, message string) { - f.bufferCh <- &fileMessageBuf{now, message} + f.bufferCh <- &fileMessageBuf{now, message, true} } func (f *file) LogWithColors(now time.Time, message, coloredMessage string) { + f.RawWithColors(now, message, coloredMessage) +} + +func (f *file) Raw(now time.Time, message string) { + f.bufferCh <- &fileMessageBuf{now, message, false} +} + +func (f *file) RawWithColors(now time.Time, message, coloredMessage string) { panic("Colors not supported in file logger") } @@ -116,7 +125,9 @@ func (f *file) write(m *fileMessageBuf) { } writer.WriteString(m.message) - writer.WriteByte('\n') + if m.nl { + writer.WriteByte('\n') + } } func (f *file) getWriter(name string) *bufio.Writer { |
