-
Notifications
You must be signed in to change notification settings - Fork 6
/
logker.go
97 lines (91 loc) · 2.35 KB
/
logker.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2020 HigKer
// Open Source: MIT License
// Author: SDing <deen.job@qq.com>
// Date: 2020/5/1 - 1:55 上午
package logker
import (
"os"
)
// This is package version
const Version = "1.2.2"
/*
____ ____ ____ ____ ____ ____
||L |||o |||g |||K |||e |||r ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
zh_CN:
LogKer是Golang语言的日志操作库.
1.控制台输出 (已经实现)
2.文件输出 (已经实现)
3.WebSocket输出 (未来将会支持)
4.网络kafka输出 (未来将会支持)
*/
// Build console Logger
/*
lev : Logging level
zone : Logging time zone
formatting : Logging format template string
at : AsyncTask Pointer
*/
func NewClog(lev level, zone logTimeZone, formatting string, at *AsyncTask) (Logger, error) {
consoleLog := &console{
// Level: logger Level
logLevel: lev,
// Zone : logger Time Zone
timeZone: zone,
tz: nil,
asyncTask: at,
}
if err := verify(formatting); err != nil {
return nil, err
}
consoleLog.formatting = formatting
consoleLog.initTime()
consoleLog.begin()
return consoleLog, nil
}
// Build File logger
/*
lev : Logging level
zone : Logging time zone
formatting : Logging format template string
at : AsyncTask Pointer
wheErr : Whether To Open A Separate ErrorFile
dir : Logging file output directory
fileName : Logging Name
size : File size
power : File system power
*/
func NewFlog(lev level, wheErr bool, zone logTimeZone, dir string, fileName string, size int64, power os.FileMode, formatting string, at *AsyncTask) (Logger, error) {
fg := &fileLog{
// logLevel: lev, logging level
logLevel: lev,
// wheError: wheErr, whether enable error alone file
wheError: wheErr,
// directory: dir, logging file save directory
directory: dir,
// fileName: fileName, logging save file name
fileName: fileName,
file: nil,
errFile: nil,
tz: nil,
// timeZone: zone, load time zone format
timeZone: zone,
// power: power, file system power
power: power,
// fileMaxSize: size, logging alone file max size
fileMaxSize: size,
}
if err := verify(formatting); err != nil {
return nil, err
}
fg.formatting = formatting
fg.asyncTask = at
fg.begin()
fg.tz = &timeZone{TimeZoneStr: fg.timeZone}
fg.file = fg.initFilePtr()
if fg.isEnableErr() {
fg.errFile = fg.initErrPtr()
}
return fg, nil
}