summaryrefslogtreecommitdiff
path: root/internal/io/dlog/loggers/stdout.go
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2021-10-15 12:38:39 +0300
committerPaul Buetow <pbuetow@mimecast.com>2021-10-15 12:38:39 +0300
commit55ba72efa4e5d2363f8e0c2cf729c596e760e1c3 (patch)
tree72618e384626d9fc368994e3f24be9e9892d0610 /internal/io/dlog/loggers/stdout.go
parentdccbee7dc355438d87baff45e054848e508b004d (diff)
parentd3549a3316a9917520ab5e6b0cd7b1846c59ad4b (diff)
merge from github.com/snonux/dtail
Diffstat (limited to 'internal/io/dlog/loggers/stdout.go')
-rw-r--r--internal/io/dlog/loggers/stdout.go54
1 files changed, 54 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..05485c6
--- /dev/null
+++ b/internal/io/dlog/loggers/stdout.go
@@ -0,0 +1,54 @@
+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)
+}
+
+func (s *stdout) LogWithColors(now time.Time, message, coloredMessage string) {
+ s.log(coloredMessage)
+}
+
+func (s *stdout) log(message string) {
+ s.mutex.Lock()
+ defer s.mutex.Unlock()
+
+ select {
+ case <-s.pauseCh:
+ // Pause until resumed.
+ <-s.resumeCh
+ default:
+ }
+
+ fmt.Println(message)
+}
+
+func (s *stdout) Pause() { s.pauseCh <- struct{}{} }
+func (s *stdout) Resume() { s.resumeCh <- struct{}{} }
+func (s *stdout) Flush() {}
+func (s *stdout) Rotate() {}
+
+func (stdout) SupportsColors() bool { return true }