-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.go
54 lines (45 loc) · 790 Bytes
/
message.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
// @author nikoeleison
package gologger
import (
"fmt"
"time"
)
// @public
// @private
// message struct
type message struct {
now time.Time
level string
file string
line int
s string
}
// message constructor
func newMsg(now time.Time, level string, file string, line int, s string) (msg *message) {
if line == 0 {
file = "???"
}
for i := len(file) - 1; i > 0; i-- {
if file[i] == '/' {
file = file[i+1:]
break
}
}
msg = &message{}
msg.now = now
msg.level = level
msg.file = file
msg.line = line
msg.s = s
return msg
}
// decorate message
func (msg *message) decorate() string {
return fmt.Sprintf(
"%s [%5s] %-30s - %s\n",
msg.now.Format("2006-01-02 15:04:05.000"),
msg.level,
fmt.Sprintf("%s:%d", msg.file, msg.line),
msg.s,
)
}