diff options
Diffstat (limited to 'internal/io/dlog')
| -rw-r--r-- | internal/io/dlog/dlog.go | 4 | ||||
| -rw-r--r-- | internal/io/dlog/loggers/file.go | 15 | ||||
| -rw-r--r-- | internal/io/dlog/loggers/fout.go | 10 | ||||
| -rw-r--r-- | internal/io/dlog/loggers/logger.go | 2 | ||||
| -rw-r--r-- | internal/io/dlog/loggers/none.go | 18 | ||||
| -rw-r--r-- | internal/io/dlog/loggers/stdout.go | 20 |
6 files changed, 52 insertions, 17 deletions
diff --git a/internal/io/dlog/dlog.go b/internal/io/dlog/dlog.go index ff2cef4..5713c1a 100644 --- a/internal/io/dlog/dlog.go +++ b/internal/io/dlog/dlog.go @@ -210,10 +210,10 @@ func (d *DLog) Devel(args ...interface{}) string { // Raw message logging. func (d *DLog) Raw(message string) string { if !config.Client.TermColorsEnable || !d.logger.SupportsColors() { - d.logger.Log(time.Now(), message) + d.logger.Raw(time.Now(), message) return message } - d.logger.LogWithColors(time.Now(), message, brush.Colorfy(message)) + d.logger.RawWithColors(time.Now(), message, brush.Colorfy(message)) return message } 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 { diff --git a/internal/io/dlog/loggers/fout.go b/internal/io/dlog/loggers/fout.go index 60c318d..6888d40 100644 --- a/internal/io/dlog/loggers/fout.go +++ b/internal/io/dlog/loggers/fout.go @@ -38,6 +38,16 @@ func (f *fout) LogWithColors(now time.Time, message, coloredMessage string) { f.file.Log(now, message) } +func (f *fout) Raw(now time.Time, message string) { + f.stdout.Raw(now, message) + f.file.Raw(now, message) +} + +func (f *fout) RawWithColors(now time.Time, message, coloredMessage string) { + f.stdout.RawWithColors(now, "", coloredMessage) + f.file.Raw(now, message) +} + func (f *fout) Flush() { f.stdout.Flush(); f.file.Flush() } func (f *fout) Pause() { f.stdout.Pause(); f.file.Pause() } func (f *fout) Resume() { f.stdout.Resume(); f.file.Resume() } diff --git a/internal/io/dlog/loggers/logger.go b/internal/io/dlog/loggers/logger.go index d4e85de..195108b 100644 --- a/internal/io/dlog/loggers/logger.go +++ b/internal/io/dlog/loggers/logger.go @@ -10,6 +10,8 @@ import ( type Logger interface { Log(now time.Time, message string) LogWithColors(now time.Time, message, messageWithColors string) + Raw(now time.Time, message string) + RawWithColors(now time.Time, message, messageWithColors string) Start(ctx context.Context, wg *sync.WaitGroup) Flush() Pause() diff --git a/internal/io/dlog/loggers/none.go b/internal/io/dlog/loggers/none.go index 270027f..973ae3c 100644 --- a/internal/io/dlog/loggers/none.go +++ b/internal/io/dlog/loggers/none.go @@ -9,13 +9,13 @@ import ( // don't log anything type none struct{} -func (none) Start(ctx context.Context, wg *sync.WaitGroup) { wg.Done() } -func (none) Log(now time.Time, message string) {} - +func (none) Start(ctx context.Context, wg *sync.WaitGroup) { wg.Done() } +func (none) Log(now time.Time, message string) {} func (none) LogWithColors(now time.Time, message, coloredMessage string) {} - -func (none) Flush() {} -func (none) Pause() {} -func (none) Resume() {} -func (none) Rotate() {} -func (none) SupportsColors() bool { return false } +func (none) Raw(now time.Time, message string) {} +func (none) RawWithColors(now time.Time, message, coloredMessage string) {} +func (none) Flush() {} +func (none) Pause() {} +func (none) Resume() {} +func (none) Rotate() {} +func (none) SupportsColors() bool { return false } diff --git a/internal/io/dlog/loggers/stdout.go b/internal/io/dlog/loggers/stdout.go index 05485c6..0369ed7 100644 --- a/internal/io/dlog/loggers/stdout.go +++ b/internal/io/dlog/loggers/stdout.go @@ -25,14 +25,22 @@ func (s *stdout) Start(ctx context.Context, wg *sync.WaitGroup) { } func (s *stdout) Log(now time.Time, message string) { - s.log(message) + s.log(message, true) } func (s *stdout) LogWithColors(now time.Time, message, coloredMessage string) { - s.log(coloredMessage) + s.log(coloredMessage, true) } -func (s *stdout) log(message string) { +func (s *stdout) Raw(now time.Time, message string) { + s.log(message, false) +} + +func (s *stdout) RawWithColors(now time.Time, message, coloredMessage string) { + s.log(coloredMessage, false) +} + +func (s *stdout) log(message string, nl bool) { s.mutex.Lock() defer s.mutex.Unlock() @@ -43,7 +51,11 @@ func (s *stdout) log(message string) { default: } - fmt.Println(message) + if nl { + fmt.Println(message) + return + } + fmt.Print(message) } func (s *stdout) Pause() { s.pauseCh <- struct{}{} } |
