-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
83 lines (69 loc) · 1.48 KB
/
models.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
78
79
80
81
82
83
package lager
import (
"encoding/json"
)
// LogLevel is a user defined variable of type int
type LogLevel int
const (
//DEBUG is a constant of user defined type LogLevel
DEBUG LogLevel = iota
INFO
WARN
ERROR
FATAL
)
// FormatLogLevel is a function which returns string format of log level
func FormatLogLevel(x LogLevel) string {
var level string
switch x {
case DEBUG:
level = "DEBUG"
case INFO:
level = "INFO"
case WARN:
level = "WARN"
case ERROR:
level = "ERROR"
case FATAL:
level = "FATAL"
}
return level
}
// MarshalJSON is a function which returns data in JSON format
func (x LogLevel) MarshalJSON() ([]byte, error) {
// var level string
var level = FormatLogLevel(x)
return json.Marshal(level)
}
// Data is a map
type Data map[string]interface{}
// LogFormat is a struct which stores details about log
type LogFormat struct {
LogLevel LogLevel `json:"level"`
Timestamp string `json:"timestamp"`
File string `json:"file"`
Message string `json:"msg"`
Data Data `json:"data,omitempty"`
}
// ToJSON which converts data of log file in to JSON file
func (log LogFormat) ToJSON() ([]byte, error) {
return json.Marshal(log)
}
// LogContent
// is struct which stores details about log
type LogContent struct {
// Level
//
Level string `json:"level"`
// Timestamp
//
Timestamp string `json:"timestamp"`
// File
//
File string `json:"file,omitempty"`
// Msg
//
Msg string `json:"msg"`
// Data
Data Data `json:"data,omitempty"`
}