-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlogline.go
53 lines (48 loc) · 846 Bytes
/
logline.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
package main
import (
"bytes"
"time"
)
type LogLine struct {
StaticTag string
Timestamp time.Time
Severity string
Hostname string
Program string
MsgPos int
Msg string
Raw []byte
}
func (l *LogLine) String() string {
if l == nil {
return ""
}
return setSeverity(l.Severity) + " " + l.Hostname + " " + l.Program + " " + l.Msg
}
func (l *LogLine) Valid() bool {
prefix := []byte(setSeverity(l.Severity) + " " + l.Hostname + " " + l.Program + " ")
return bytes.HasPrefix(l.Raw[33:], prefix)
}
func setSeverity(in string) (out string) {
switch in {
case "emergency":
out = "0"
case "alert":
out = "1"
case "critical":
out = "2"
case "error":
out = "3"
case "warning":
out = "4"
case "notice":
out = "5"
case "info":
out = "6"
case "debug":
out = "7"
default:
out = "0"
}
return
}