1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

cmd/gocq: adapt MiraiGo Logger interface

This commit is contained in:
wdvxdr 2022-03-02 22:08:47 +08:00
parent c00e07dec9
commit 4d8c55aca1
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
3 changed files with 34 additions and 21 deletions

View File

@ -130,7 +130,6 @@ func Main() {
log.Info("当前版本:", base.Version) log.Info("当前版本:", base.Version)
if base.Debug { if base.Debug {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
log.Warnf("已开启Debug模式.") log.Warnf("已开启Debug模式.")
// log.Debugf("开发交流群: 192548878") // log.Debugf("开发交流群: 192548878")
} }
@ -383,22 +382,36 @@ func newClient() *client.QQClient {
} }
log.Infof("读取到 %v 个自定义地址.", len(addr)) log.Infof("读取到 %v 个自定义地址.", len(addr))
} }
c.OnLog(func(c *client.QQClient, e *client.LogEvent) { c.SetLogger(protocolLogger{})
switch e.Type { return c
case "INFO": }
log.Info("Protocol -> " + e.Message)
case "ERROR": type protocolLogger struct{}
log.Error("Protocol -> " + e.Message)
case "DEBUG": const fromProtocol = "Protocol -> "
log.Debug("Protocol -> " + e.Message)
case "DUMP": func (p protocolLogger) Info(format string, arg ...any) {
log.Infof(fromProtocol+format, arg...)
}
func (p protocolLogger) Warning(format string, arg ...any) {
log.Warnf(fromProtocol+format, arg...)
}
func (p protocolLogger) Debug(format string, arg ...any) {
log.Debugf(fromProtocol+format, arg...)
}
func (p protocolLogger) Error(format string, arg ...any) {
log.Errorf(fromProtocol+format, arg...)
}
func (p protocolLogger) Dump(data []byte, format string, arg ...any) {
if !global.PathExists(global.DumpsPath) { if !global.PathExists(global.DumpsPath) {
_ = os.MkdirAll(global.DumpsPath, 0o755) _ = os.MkdirAll(global.DumpsPath, 0o755)
} }
dumpFile := path.Join(global.DumpsPath, fmt.Sprintf("%v.dump", time.Now().Unix())) dumpFile := path.Join(global.DumpsPath, fmt.Sprintf("%v.dump", time.Now().Unix()))
log.Errorf("出现错误 %v. 详细信息已转储至文件 %v 请连同日志提交给开发者处理", e.Message, dumpFile) message := fmt.Sprintf(format, arg...)
_ = os.WriteFile(dumpFile, e.Dump, 0o644) log.Errorf("出现错误 %v. 详细信息已转储至文件 %v 请连同日志提交给开发者处理", message, dumpFile)
} _ = os.WriteFile(dumpFile, data, 0o644)
})
return c
} }

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.18
require ( require (
github.com/Microsoft/go-winio v0.5.1 github.com/Microsoft/go-winio v0.5.1
github.com/Mrs4s/MiraiGo v0.0.0-20220301082018-d9f803837f49 github.com/Mrs4s/MiraiGo v0.0.0-20220302134146-348e317a3400
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
github.com/fumiama/go-hide-param v0.1.4 github.com/fumiama/go-hide-param v0.1.4
github.com/gabriel-vasile/mimetype v1.4.0 github.com/gabriel-vasile/mimetype v1.4.0

4
go.sum
View File

@ -1,7 +1,7 @@
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY= github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Mrs4s/MiraiGo v0.0.0-20220301082018-d9f803837f49 h1:IIEX0ue2VBA7kGOR1RpdQfPPKfeB4gWine47QXUyzTY= github.com/Mrs4s/MiraiGo v0.0.0-20220302134146-348e317a3400 h1:5e0KDN118/RKItDmUcJyCkyyK/EGItYYJ5TVX/jb6xM=
github.com/Mrs4s/MiraiGo v0.0.0-20220301082018-d9f803837f49/go.mod h1:qJWkRO5vry/sUHthX5kh6go2llYIVAJ+Mq8p+N/FW+8= github.com/Mrs4s/MiraiGo v0.0.0-20220302134146-348e317a3400/go.mod h1:qJWkRO5vry/sUHthX5kh6go2llYIVAJ+Mq8p+N/FW+8=
github.com/RomiChan/protobuf v0.0.0-20220227114948-643565fff248 h1:1jRB6xuBKwfgZrg0bA7XJin0VeNwG9iJKx9RXwDobt4= github.com/RomiChan/protobuf v0.0.0-20220227114948-643565fff248 h1:1jRB6xuBKwfgZrg0bA7XJin0VeNwG9iJKx9RXwDobt4=
github.com/RomiChan/protobuf v0.0.0-20220227114948-643565fff248/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE= github.com/RomiChan/protobuf v0.0.0-20220227114948-643565fff248/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0= github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=