-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstance.go
64 lines (51 loc) · 972 Bytes
/
instance.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
package golog
import (
"sync"
wr "github.com/mreza0100/golog/writer"
)
type InitOpns struct {
LogPath string
Name string
WithTime bool
DebugMode bool
ClearLogFile bool
wr wr.Writer
}
type hookT []func(*Core) interface{}
func New(opts InitOpns) *Core {
var (
addLog = make([]interface{}, 0, 1)
hooks = make(hookT, 0, 1)
isDebugMode = opts.DebugMode
writer wr.Writer
)
{
writer = wr.New(wr.NewOpts{
LogPath: opts.LogPath,
})
if opts.ClearLogFile {
writer.RemoveFile()
}
}
addLog = append(addLog, "[[ "+opts.Name+" ]]")
if opts.WithTime {
hooks = append(hooks, timeHook)
}
data := &dataT{
LogPath: opts.LogPath,
AddLog: addLog,
Hooks: hooks,
mu: &sync.Mutex{},
}
lgr := &Core{
IsDebugMode: true, // always working
Data: data,
WR: writer,
}
lgr.Debug = &Core{
IsDebugMode: isDebugMode,
WR: writer,
Data: data,
}
return lgr
}