-
Notifications
You must be signed in to change notification settings - Fork 16
/
logger.go
77 lines (63 loc) · 1.4 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"io"
"os"
"strings"
)
var (
logwriter io.Writer
)
func initLogging(stderr bool) {
if stderr {
logwriter = os.Stderr
} else {
logwriter = os.Stdout
}
}
func logRaw(format string, args ...interface{}) {
fmt.Fprintf(logwriter, format+"\n", args...)
}
func logTitle(format string, args ...interface{}) {
logInfo(format, args...)
title := strings.Repeat("-", len(fmt.Sprintf(format, args...)))
if len(title) > 0 {
logInfo(title)
}
}
func logResultsIntPostfix(label string, value int, postfix string) {
logInfo(fmt.Sprintf("%-15s %15s %s", label, formatInt(value), postfix))
}
func logResults(label, value string) {
logInfo(fmt.Sprintf("%-15s %15s", label, value))
}
func logResultsPostfix(label, value, postfix string) {
logInfo(fmt.Sprintf("%-15s %15s %s", label, value, postfix))
}
func logInfo(format string, args ...interface{}) {
if !StartParams.Quiet {
logRaw(format, args...)
}
}
func logWarn(format string, args ...interface{}) {
format = "[WARN] " + format
if !StartParams.Quiet {
logRaw(format, args...)
}
}
func logError(format string, args ...interface{}) {
format = "[ERROR] " + format
if !StartParams.Quiet {
logRaw(format, args...)
}
}
func logFatal(format string, args ...interface{}) {
format = "\n[FATAL] " + format
logRaw(format, args...)
os.Exit(1)
}
func logFatalError(err error) {
if err != nil {
logFatal(err.Error())
}
}