+14
-7
internal/log/log.go
+14
-7
internal/log/log.go
···
6
6
"log"
7
7
"os"
8
8
"strings"
9
+
"time"
9
10
)
10
11
11
12
var (
···
21
22
verboseWriter = os.Stdout
22
23
}
23
24
24
-
infoLog = log.New(infoWriter, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
25
-
verboseLog = log.New(verboseWriter, "VERBOSE: ", log.Ldate|log.Ltime|log.Lshortfile)
26
-
errorLog = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
25
+
// Use no flags, we'll add our own ISO 8601 timestamps
26
+
infoLog = log.New(infoWriter, "", 0)
27
+
verboseLog = log.New(verboseWriter, "", 0)
28
+
errorLog = log.New(os.Stderr, "", 0)
29
+
}
30
+
31
+
// timestamp returns current time in ISO 8601 format
32
+
func timestamp() string {
33
+
return time.Now().Format(time.RFC3339)
27
34
}
28
35
29
36
func Verbose(format string, v ...interface{}) {
30
-
verboseLog.Printf(format, v...)
37
+
verboseLog.Printf("%s [VERBOSE] %s", timestamp(), fmt.Sprintf(format, v...))
31
38
}
32
39
33
40
func Info(format string, v ...interface{}) {
34
-
infoLog.Printf(format, v...)
41
+
infoLog.Printf("%s [INFO] %s", timestamp(), fmt.Sprintf(format, v...))
35
42
}
36
43
37
44
func Error(format string, v ...interface{}) {
38
-
errorLog.Printf(format, v...)
45
+
errorLog.Printf("%s [ERROR] %s", timestamp(), fmt.Sprintf(format, v...))
39
46
}
40
47
41
48
func Fatal(format string, v ...interface{}) {
42
-
errorLog.Fatalf(format, v...)
49
+
errorLog.Fatalf("%s [FATAL] %s", timestamp(), fmt.Sprintf(format, v...))
43
50
}
44
51
45
52
// Banner prints a startup banner