-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathslog_manager.go
More file actions
98 lines (78 loc) · 1.67 KB
/
slog_manager.go
File metadata and controls
98 lines (78 loc) · 1.67 KB
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
98
package slog
import (
"fmt"
"time"
)
const (
LOG_VERSION = "slog-v0.1"
LOG_MAJOR = 3
LOG_MINOR = 0
LOG_BUILD = 1
)
type Level int
const (
INFO Level = iota
DEBUG
WARNING
ERROR
)
var (
levelStrings = [...]string{"INFO", "DEBG", "WARN", "EROR"}
)
const LogBufferLength = 65535
func (l Level) String() string {
if l < 0 || int(l) > len(levelStrings) {
return "UNKNOWN"
}
return levelStrings[int(l)]
}
type LogRecord struct {
Level Level
Created time.Time
logfile bool
Name string
Message string
}
type LogManager struct {
Name string
level Level
}
func init() {
InitLogWriter()
}
func (this *LogManager) post_log(debuglv Level, is_log_file bool, name string, format string, args ...interface{}) {
if this.level > debuglv {
return
}
var msg string
if len(args) > 0 {
msg = fmt.Sprintf(format, args...)
} else {
msg = format
}
rec := &LogRecord{
Level: debuglv,
logfile: is_log_file,
Created: time.Now(),
Name: name,
Message: msg,
}
_log_writer.LogWrite(rec)
}
var _log_manager_default = &LogManager{"default", INFO}
func LogInfo(name string, format string, args ...interface{}) {
_log_manager_default.post_log(INFO, false, name, format, args...)
}
func LogDebug(name string, format string, args ...interface{}) {
_log_manager_default.post_log(DEBUG, true, name, format, args...)
}
func LogWarning(name string, format string, args ...interface{}) {
_log_manager_default.post_log(WARNING, true, name, format, args...)
}
func LogError(name string, format string, args ...interface{}) {
_log_manager_default.post_log(ERROR, true, name, format, args...)
}
func Close() {
_log_writer.LogWrite(nil)
_log_writer.end_wait.Wait()
}