summaryrefslogtreecommitdiff
path: root/internal/io/dlog/loggers/stdout.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/io/dlog/loggers/stdout.go')
-rw-r--r--internal/io/dlog/loggers/stdout.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/internal/io/dlog/loggers/stdout.go b/internal/io/dlog/loggers/stdout.go
new file mode 100644
index 0000000..ef30855
--- /dev/null
+++ b/internal/io/dlog/loggers/stdout.go
@@ -0,0 +1,72 @@
+package loggers
+
+import (
+ "context"
+ "fmt"
+ "sync"
+ "time"
+)
+
+type stdout struct {
+ pauseCh chan struct{}
+ resumeCh chan struct{}
+ mutex sync.Mutex
+}
+
+func newStdout() *stdout {
+ return &stdout{
+ pauseCh: make(chan struct{}),
+ resumeCh: make(chan struct{}),
+ }
+}
+
+func (s *stdout) Start(ctx context.Context, wg *sync.WaitGroup) {
+ wg.Done()
+}
+
+func (s *stdout) Log(now time.Time, message string) {
+ s.log(message, true)
+}
+
+func (s *stdout) LogWithColors(now time.Time, message, coloredMessage string) {
+ s.log(coloredMessage, true)
+}
+
+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()
+
+ select {
+ case <-s.pauseCh:
+ // Pause until resumed.
+ <-s.resumeCh
+ default:
+ }
+
+ if nl {
+ fmt.Println(message)
+ return
+ }
+ fmt.Print(message)
+}
+
+func (s *stdout) Pause() { s.pauseCh <- struct{}{} }
+func (s *stdout) Resume() { s.resumeCh <- struct{}{} }
+
+func (s *stdout) Flush() {
+ // This is empty because it isn't doing anything but has to satisfy the interface.
+}
+
+func (s *stdout) Rotate() {
+ // This is empty because it isn't doing anything but has to satisfy the interface.
+}
+
+func (stdout) SupportsColors() bool { return true }