-
Notifications
You must be signed in to change notification settings - Fork 5
/
log.go
69 lines (55 loc) · 1.59 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
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 (
"fmt"
"os"
"sort"
"strings"
"time"
)
func formatLog(command string, params map[string]string, value string) string {
if len(params) > 0 {
p := []string{}
for k, v := range params {
p = append(p, fmt.Sprintf("%v=%v", k, v))
}
sort.Strings(p)
return fmt.Sprintf("::%v %v::%v\n", command, strings.Join(p, ","), value)
}
return fmt.Sprintf("::%v::%v\n", command, value)
}
func Log(command string, params map[string]string, value string) {
fmt.Fprint(os.Stdout, formatLog(command, params, value))
}
func LogSetEnv(name, value string) {
Log("set-env", map[string]string{"name": name}, value)
}
func LogSetOutput(name, value string) {
Log("set-output", map[string]string{"name": name}, value)
}
func LogAddSystemPath(path string) {
Log("add-path", nil, path)
}
// You must create a secret named `ACTIONS_STEP_DEBUG` with the value `true`
// to see the debug messages set by this command in the log.
func LogDebug(message string, params map[string]string) {
Log("debug", params, message)
}
func LogWarning(message string, params map[string]string) {
Log("warning", params, message)
}
func LogError(message string, params map[string]string) {
Log("error", params, message)
}
func LogAddMask(value string) {
Log("add-mask", nil, value)
}
func Infof(format string, a ...interface{}) {
elapsed := time.Now().Sub(startTime)
fmt.Fprintf(os.Stdout, "%02d:%02d:%02d] %v\n",
int(elapsed.Hours()), int(elapsed.Minutes()), int(elapsed.Seconds()),
fmt.Sprintf(format, a...))
}
func Fatalf(format string, a ...interface{}) {
LogError(fmt.Sprintf(format, a...), nil)
os.Exit(1)
}