-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxylog.go
46 lines (40 loc) · 909 Bytes
/
proxylog.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
package log
import (
"fmt"
"github.com/fatih/color"
"github.com/lqqyt2423/go-mitmproxy/proxy"
log "github.com/sirupsen/logrus"
)
type LogStruct struct {
name string
flow *proxy.Flow
}
func InitLog(name string, f *proxy.Flow) LogStruct {
return LogStruct{name, f}
}
func (l *LogStruct) Infof(format string, args ...any) {
log.Infof(
"%s%s: %s\n",
color.BlueString("[%s]", l.name),
color.CyanString(
"[%s][%s][%s]",
l.flow.ConnContext.ClientConn.Conn.RemoteAddr(),
l.flow.Request.Method,
l.flow.Request.URL.String(),
),
fmt.Sprintf(format, args...),
)
}
func (l *LogStruct) Errorf(format string, args ...interface{}) {
log.Errorf(
"%s%s: %s\n",
color.RedString("[%s]", l.name),
color.CyanString(
"[%s][%s][%s]",
l.flow.ConnContext.ClientConn.Conn.RemoteAddr(),
l.flow.Request.Method,
l.flow.Request.URL.String(),
),
fmt.Sprintf(format, args...),
)
}