-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (59 loc) · 1.9 KB
/
main.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"bufio"
"os"
"time"
)
// Version contains the binary version. This is added at build time.
var Version = "uncommitted"
// WantsDateStamp represents whether the output should contain the YYYY-MM-DD
// representation of the date at which the output line was received.
var WantsDateStamp = true
// WantsTimeStamp represents whether the output should contain the
// HH:MM:SS.NNNNNN representation of the time at which the output line was
// received.
var WantsTimeStamp = true
// WantsColors represents whether the output should contain colors if the time
// between two subsequent lines "took too long".
// This is automatically toggled.
var WantsColors = false
// WantsBuffered represents whether the user would prefer output to be buffered,
// which makes it be processed a bit faster, or not.
// Running:
// yes | head -n ... | tstdin
// Unbuffered processes ~1.1 Mb/s
// Buffered processes ~1.4 Mb/s
var WantsBuffered = false
// FlushEvery represents, IFF WantsBuffered is set, after how many milliseconds
// STDOUT gets flushed.
var FlushEvery = 500
// ErrorAfter represents after how many ms to mark a line as having been output
// after "way too long". If colors are enabled, this is shown in red.
var ErrorAfter int = 60000
// WarnAfter represents after how many ms to mark a line as having been output
// after "a bit too long". If colors are enabled, this is whoen in yellow.
var WarnAfter int = 1000
func main() {
dealWithArgs()
if WantsBuffered {
var stdOut = bufio.NewWriterSize(os.Stdout, 8192)
ticker := time.NewTicker(time.Duration(FlushEvery) * time.Millisecond)
done := make(chan bool)
go func() {
for {
select {
case <-done:
return
case <-ticker.C:
stdOut.Flush()
}
}
}()
timestamp(realClock{}, os.Stdin, stdOut, WantsColors)
ticker.Stop()
done <- true
stdOut.Flush()
} else {
timestamp(realClock{}, os.Stdin, os.Stdout, WantsColors)
}
}