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:
parent
c00e07dec9
commit
4d8c55aca1
@ -130,7 +130,6 @@ func Main() {
|
||||
log.Info("当前版本:", base.Version)
|
||||
if base.Debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.SetReportCaller(true)
|
||||
log.Warnf("已开启Debug模式.")
|
||||
// log.Debugf("开发交流群: 192548878")
|
||||
}
|
||||
@ -383,22 +382,36 @@ func newClient() *client.QQClient {
|
||||
}
|
||||
log.Infof("读取到 %v 个自定义地址.", len(addr))
|
||||
}
|
||||
c.OnLog(func(c *client.QQClient, e *client.LogEvent) {
|
||||
switch e.Type {
|
||||
case "INFO":
|
||||
log.Info("Protocol -> " + e.Message)
|
||||
case "ERROR":
|
||||
log.Error("Protocol -> " + e.Message)
|
||||
case "DEBUG":
|
||||
log.Debug("Protocol -> " + e.Message)
|
||||
case "DUMP":
|
||||
c.SetLogger(protocolLogger{})
|
||||
return c
|
||||
}
|
||||
|
||||
type protocolLogger struct{}
|
||||
|
||||
const fromProtocol = "Protocol -> "
|
||||
|
||||
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) {
|
||||
_ = os.MkdirAll(global.DumpsPath, 0o755)
|
||||
}
|
||||
dumpFile := path.Join(global.DumpsPath, fmt.Sprintf("%v.dump", time.Now().Unix()))
|
||||
log.Errorf("出现错误 %v. 详细信息已转储至文件 %v 请连同日志提交给开发者处理", e.Message, dumpFile)
|
||||
_ = os.WriteFile(dumpFile, e.Dump, 0o644)
|
||||
}
|
||||
})
|
||||
return c
|
||||
message := fmt.Sprintf(format, arg...)
|
||||
log.Errorf("出现错误 %v. 详细信息已转储至文件 %v 请连同日志提交给开发者处理", message, dumpFile)
|
||||
_ = os.WriteFile(dumpFile, data, 0o644)
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
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/fumiama/go-hide-param v0.1.4
|
||||
github.com/gabriel-vasile/mimetype v1.4.0
|
||||
|
4
go.sum
4
go.sum
@ -1,7 +1,7 @@
|
||||
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/Mrs4s/MiraiGo v0.0.0-20220301082018-d9f803837f49 h1:IIEX0ue2VBA7kGOR1RpdQfPPKfeB4gWine47QXUyzTY=
|
||||
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 h1:5e0KDN118/RKItDmUcJyCkyyK/EGItYYJ5TVX/jb6xM=
|
||||
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/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE=
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
|
||||
|
Loading…
x
Reference in New Issue
Block a user