-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
80 lines (66 loc) · 1.33 KB
/
config.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
package logger
import (
"io"
"os"
)
type Place int
type ContentType string
type Level int
const (
ToConsole Place = 1 << iota
ToFile
)
const (
FormatJson ContentType = "Json"
FormatText ContentType = "Text"
)
const (
Alert Level = iota
Error
Warn
Info
Debug
)
var LogLevels = map[string]Level{
"Alert": Alert,
"Error": Error,
"Warn": Warn,
"Info": Info,
"Debug": Debug,
}
var defaultCacheSize = 1024
type LogConfig struct {
LogPlace Place
level Level
PlaceContentType map[Place]ContentType
PlaceIoWriter map[Place]io.Writer
CacheSize int
}
func NewConfig(p Place) *LogConfig {
c := new(LogConfig)
c.LogPlace = p
c.PlaceContentType = make(map[Place]ContentType)
c.PlaceIoWriter = make(map[Place]io.Writer)
c.PlaceIoWriter[ToConsole] = os.Stdout
c.CacheSize = defaultCacheSize
return c
}
func (c *LogConfig) SetCententType(place Place, contenttype ContentType) *LogConfig {
c.PlaceContentType[place] = contenttype
return c
}
func (c *LogConfig) SetIoWriter(place Place, io_writer io.Writer) *LogConfig {
c.PlaceIoWriter[place] = io_writer
return c
}
func (c *LogConfig) SetLevel(level Level) *LogConfig {
c.level = level
return c
}
func (c *LogConfig) GetLevel() Level {
return c.level
}
func (c *LogConfig) SetCacheSize(size int) *LogConfig {
c.CacheSize = size
return c
}