-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.go
47 lines (40 loc) · 1.19 KB
/
log.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
package captainslog
import (
"context"
"fmt"
"os/exec"
"strings"
"time"
)
var announceOnce bool
// Debugf writes a debug level log entry.
func Debugf(ctx context.Context, format string, args ...interface{}) {
log(ctx, fmt.Sprintf("debug. "+format, args...))
}
// Errorf writes a debug level log entry.
func Errorf(ctx context.Context, format string, args ...interface{}) {
log(ctx, fmt.Sprintf("error. "+format, args...))
}
// Warningf writes a debug level log entry.
func Warningf(ctx context.Context, format string, args ...interface{}) {
log(ctx, fmt.Sprintf("warning. "+format, args...))
}
func log(ctx context.Context, s string) {
if !announceOnce {
announceOnce = true
now := time.Now()
stardate := speakn(now.Format("060201"))
announce := fmt.Sprintf("Captains log star date %s point %s.", stardate, speakn(fmt.Sprintf("%d", now.Hour())))
exec.CommandContext(ctx, "say", announce).Run()
} else {
exec.CommandContext(ctx, "say", "-v", "Daniel", "Captains log, supplemental.").Run()
}
exec.CommandContext(ctx, "say", "-v", "Daniel", s).Run()
}
func speakn(s string) string {
var nos []string
for i := range s {
nos = append(nos, string(s[i]))
}
return strings.Join(nos, " ")
}