-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
66 lines (52 loc) · 1.25 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
// Logs
// Any utils to log events must be placed here
package main
import (
"fmt"
"log"
"net/http"
"time"
)
var (
log_debug_enabled = false
log_requests_enabled = false
)
func SetDebugLogEnabled(enabled bool) {
log_debug_enabled = enabled
}
func SetRequestLogEnabled(enabled bool) {
log_requests_enabled = enabled
}
func LogLine(line string) {
log.Println(line)
}
func LogWarning(line string) {
LogLine("[WARNING] " + line)
}
func LogInfo(line string) {
LogLine("[INFO] " + line)
}
func LogSecurity(line string) {
LogLine("[SECURITY] " + line)
}
func LogError(err error) {
LogLine("[ERROR] " + err.Error())
}
func LogTaskError(task_id uint64, err string) {
LogLine("[TASK #" + fmt.Sprint(task_id) + "] [ERROR] " + err)
}
func LogTaskDebug(task_id uint64, err string) {
if log_debug_enabled {
LogLine("[TASK #" + fmt.Sprint(task_id) + "] [DEBUG] " + err)
}
}
func LogDebug(line string) {
if log_debug_enabled {
LogLine("[DEBUG] " + line)
}
}
func LogRequest(r *http.Request, statusCode int, duration time.Duration) {
if log_requests_enabled {
LogLine("[REQUEST] (From: " + GetClientIP(r) + ") " + r.Method + " " + r.URL.Path + " (" + fmt.Sprint(statusCode) + " " + http.StatusText(statusCode) + ") (" + duration.String() + ")")
}
}