-
Notifications
You must be signed in to change notification settings - Fork 23
/
record.go
75 lines (69 loc) · 1.97 KB
/
record.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
package logging
import (
"fmt"
"time"
)
// A LogRecord instance represents an event being logged.
// LogRecord instances are created every time something is logged. They
// contain all the information pertinent to the event being logged. The
// main information passed in is in Message and Args, which are combined
// using fmt.Sprintf() or fmt.Sprint(), depending on value of UseFormat flag,
// to create the message field of the record. The record also includes
// information such as when the record was created, the source line where
// the logging call was made, and any exception information to be logged.
type LogRecord struct {
CreatedTime time.Time
AscTime string
Name string
Level LogLevelType
PathName string
FileName string
LineNo uint32
FuncName string
Format string
UseFormat bool
Args []interface{}
Message string
}
// Initialize a logging record with interesting information.
func NewLogRecord(
name string,
level LogLevelType,
pathName string,
fileName string,
lineNo uint32,
funcName string,
format string,
useFormat bool,
args []interface{}) *LogRecord {
return &LogRecord{
CreatedTime: time.Now(),
Name: name,
Level: level,
PathName: pathName,
FileName: fileName,
LineNo: lineNo,
FuncName: funcName,
Format: format,
UseFormat: useFormat,
Args: args,
Message: "",
}
}
// Return the string representation for this LogRecord.
func (self *LogRecord) String() string {
return fmt.Sprintf("<LogRecord: %s, %s, %s, %d, \"%s\">",
self.Name, self.Level, self.PathName, self.LineNo, self.Message)
}
// Return the message for this LogRecord.
// The message is composed of the Message and any user-supplied arguments.
func (self *LogRecord) GetMessage() string {
if len(self.Message) == 0 {
if self.UseFormat {
self.Message = fmt.Sprintf(self.Format, self.Args...)
} else {
self.Message = fmt.Sprint(self.Args...)
}
}
return self.Message
}