summaryrefslogtreecommitdiff
path: root/internal/io/dlog/loggers/fout.go
blob: 6888d40c4e8d96e15e50f572ab01a95003db154b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package loggers

import (
	"context"
	"sync"
	"time"
)

type fout struct {
	file   *file
	stdout *stdout
}

// Logs to both, a file and stdout
func newFout(strategy Strategy) *fout {
	return &fout{file: newFile(strategy), stdout: newStdout()}
}

func (f *fout) Start(ctx context.Context, wg *sync.WaitGroup) {
	go func() {
		defer wg.Done()

		var wg2 sync.WaitGroup
		wg2.Add(2)
		f.file.Start(ctx, &wg2)
		f.stdout.Start(ctx, &wg2)
		wg2.Wait()
	}()
}

func (f *fout) Log(now time.Time, message string) {
	f.stdout.Log(now, message)
	f.file.Log(now, message)
}

func (f *fout) LogWithColors(now time.Time, message, coloredMessage string) {
	f.stdout.LogWithColors(now, "", coloredMessage)
	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() }
func (f *fout) Rotate() { f.file.Rotate() }

func (fout) SupportsColors() bool { return true }