-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
56 lines (45 loc) · 985 Bytes
/
logger.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
package main
import (
"log"
"github.com/martinlindhe/notify"
)
type Logger interface {
Info(msg string)
Error(err string)
SuccessfulBuild()
Notification(title string, msg string)
}
type RealLogger struct {
useNotification bool
useStdout bool
}
func (l RealLogger) Info(msg string) {
if l.useStdout {
log.Println(msg)
}
}
func (l RealLogger) Error(err string) {
if l.useStdout {
log.Println(err)
}
if l.useNotification {
notify.Notify("Dotcopy", "Error", err, "")
}
}
func (l RealLogger) SuccessfulBuild() {
if l.useStdout {
log.Println("Dotfiles compiled successfully!")
}
if l.useNotification {
notify.Notify("Dotcopy", "Dotfiles compiled successfully!", "", "")
}
}
func (l RealLogger) Notification(title string, msg string) {
if l.useNotification {
// send notification
notify.Notify("Dotcopy", title, msg, "")
}
}
func MakeRealLogger(useNotification bool, useStdout bool) Logger {
return RealLogger{useNotification, useStdout}
}