-
Notifications
You must be signed in to change notification settings - Fork 63
/
log.go
executable file
·65 lines (53 loc) · 1.18 KB
/
log.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
package elog
import (
"bytes"
"github.com/op/go-logging"
"github.com/schollz/progressbar/v3"
"hostscan/vars"
"time"
)
var format logging.Formatter
func init() {
format = logging.MustStringFormatter(`%{color}[%{level:.4s}]%{color:reset} [%{time:15:04:05}] %{message}`)
vars.ProcessBar = progressbar.NewOptions(0)
}
type LogFiller struct {
//record *logging.Record
msg string
}
func NewFiller(record *logging.Record) *LogFiller {
return &LogFiller{msg: toMsg(record)}
}
func toMsg(record *logging.Record) string {
buf := new(bytes.Buffer)
format.Format(4, record, buf)
return buf.String()
}
func LogWithLevel(msg string, level logging.Level) {
record := &logging.Record{
Time: time.Now(),
//Module: "",
Args: []interface{}{msg},
Level: level,
}
//println(msg)
vars.ProcessBar.WriteLog(toMsg(record))
}
func Info(msg string) {
LogWithLevel(msg, logging.INFO)
}
func Debug(msg string) {
LogWithLevel(msg, logging.DEBUG)
}
func Warn(msg string) {
LogWithLevel(msg, logging.WARNING)
}
func Error(msg string) {
LogWithLevel(msg, logging.ERROR)
}
func Notice(msg string) {
LogWithLevel(msg, logging.NOTICE)
}
func Critical(msg string) {
LogWithLevel(msg, logging.CRITICAL)
}