Skip to content

Commit 9934d8e

Browse files
committed
code organize with responbility elements
1 parent f80d281 commit 9934d8e

File tree

3 files changed

+68
-64
lines changed

3 files changed

+68
-64
lines changed

file_receiver.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import (
1616
"aahframework.org/essentials.v0"
1717
)
1818

19-
var _ Receiver = &FileReceiver{}
19+
var (
20+
// backupTimeFormat is used for timestamp with filename on rotation
21+
backupTimeFormat = "2006-01-02-15-04-05.000"
22+
23+
_ Receiver = &FileReceiver{}
24+
)
2025

2126
// FileReceiver writes the log entry into file.
2227
type FileReceiver struct {
@@ -193,7 +198,7 @@ func (f *FileReceiver) backupFileName() string {
193198
if f.isUTC {
194199
t = t.UTC()
195200
}
196-
return filepath.Join(dir, fmt.Sprintf("%s-%s%s", baseName, t.Format(BackupTimeFormat), ext))
201+
return filepath.Join(dir, fmt.Sprintf("%s-%s%s", baseName, t.Format(backupTimeFormat), ext))
197202
}
198203

199204
func (f *FileReceiver) getDay() int {

formatter.go

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,70 @@ import (
1111
"strings"
1212
)
1313

14+
// Format flags used to define log message format for each log entry
15+
const (
16+
FmtFlagLevel fmtFlag = iota
17+
FmtFlagTime
18+
FmtFlagUTCTime
19+
FmtFlagLongfile
20+
FmtFlagShortfile
21+
FmtFlagLine
22+
FmtFlagMessage
23+
FmtFlagCustom
24+
FmtFlagUnknown
25+
)
26+
1427
const (
1528
textFmt = "text"
1629
jsonFmt = "json"
1730
)
1831

19-
// FlagPart is indiviual flag details
20-
// For e.g.:
21-
// part := FlagPart{
22-
// Flag: fmtFlagTime,
23-
// Name: "time",
24-
// Format: "2006-01-02 15:04:05.000",
25-
// }
26-
type FlagPart struct {
27-
Flag fmtFlag
28-
Name string
29-
Format string
30-
}
32+
type (
33+
// FlagPart is indiviual flag details
34+
// For e.g.:
35+
// part := FlagPart{
36+
// Flag: fmtFlagTime,
37+
// Name: "time",
38+
// Format: "2006-01-02 15:04:05.000",
39+
// }
40+
FlagPart struct {
41+
Flag fmtFlag
42+
Name string
43+
Format string
44+
}
45+
46+
// FmtFlag type definition
47+
fmtFlag uint8
48+
)
49+
50+
var (
51+
// DefaultPattern is default log entry pattern in aah/log. Only applicable to
52+
// text formatter.
53+
// For e.g:
54+
// 2006-01-02 15:04:05.000 INFO This is my message
55+
DefaultPattern = "%time:2006-01-02 15:04:05.000 %level:-5 %message"
56+
57+
// FmtFlags is the list of log format flags supported by aah/log library
58+
// Usage of flag order is up to format composition.
59+
// level - outputs INFO, DEBUG, ERROR, so on
60+
// time - outputs local time as per format supplied
61+
// utctime - outputs UTC time as per format supplied
62+
// longfile - outputs full file name: /a/b/c/d.go
63+
// shortfile - outputs final file name element: d.go
64+
// line - outputs file line number: L23
65+
// message - outputs given message along supplied arguments if they present
66+
// custom - outputs string as-is into log entry
67+
FmtFlags = map[string]fmtFlag{
68+
"level": FmtFlagLevel,
69+
"time": FmtFlagTime,
70+
"utctime": FmtFlagUTCTime,
71+
"longfile": FmtFlagLongfile,
72+
"shortfile": FmtFlagShortfile,
73+
"line": FmtFlagLine,
74+
"message": FmtFlagMessage,
75+
"custom": FmtFlagCustom,
76+
}
77+
)
3178

3279
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
3380
// textFormatter

log.go

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ import (
3434
"aahframework.org/config.v0"
3535
)
3636

37-
type (
38-
// FmtFlag type definition
39-
fmtFlag uint8
40-
41-
// Level type definition
42-
level uint8
43-
)
37+
// Level type definition
38+
type level uint8
4439

4540
// Log Level definition
4641
const (
@@ -54,53 +49,10 @@ const (
5449
LevelUnknown
5550
)
5651

57-
// Format flags used to define log message format for each log entry
58-
const (
59-
FmtFlagLevel fmtFlag = iota
60-
FmtFlagTime
61-
FmtFlagUTCTime
62-
FmtFlagLongfile
63-
FmtFlagShortfile
64-
FmtFlagLine
65-
FmtFlagMessage
66-
FmtFlagCustom
67-
FmtFlagUnknown
68-
)
69-
7052
var (
7153
// Version no. of aahframework.org/log library
7254
Version = "0.5"
7355

74-
// FmtFlags is the list of log format flags supported by aah/log library
75-
// Usage of flag order is up to format composition.
76-
// level - outputs INFO, DEBUG, ERROR, so on
77-
// time - outputs local time as per format supplied
78-
// utctime - outputs UTC time as per format supplied
79-
// longfile - outputs full file name: /a/b/c/d.go
80-
// shortfile - outputs final file name element: d.go
81-
// line - outputs file line number: L23
82-
// message - outputs given message along supplied arguments if they present
83-
// custom - outputs string as-is into log entry
84-
FmtFlags = map[string]fmtFlag{
85-
"level": FmtFlagLevel,
86-
"time": FmtFlagTime,
87-
"utctime": FmtFlagUTCTime,
88-
"longfile": FmtFlagLongfile,
89-
"shortfile": FmtFlagShortfile,
90-
"line": FmtFlagLine,
91-
"message": FmtFlagMessage,
92-
"custom": FmtFlagCustom,
93-
}
94-
95-
// DefaultPattern is default log entry pattern in aah/log. Only applicable to
96-
// text formatter.
97-
// For e.g:
98-
// 2006-01-02 15:04:05.000 INFO This is my message
99-
DefaultPattern = "%time:2006-01-02 15:04:05.000 %level:-5 %message"
100-
101-
// BackupTimeFormat is used for timestamp with filename on rotation
102-
BackupTimeFormat = "2006-01-02-15-04-05.000"
103-
10456
// ErrLogReceiverIsNil returned when suppiled receiver is nil.
10557
ErrLogReceiverIsNil = errors.New("log: receiver is nil")
10658

0 commit comments

Comments
 (0)