go-cqhttp icon indicating copy to clipboard operation
go-cqhttp copied to clipboard

replace logrus with internal/log

Open wdvxdr1123 opened this issue 4 years ago • 2 comments

reduce binary size about 100k

shortcoming:

  1. unfriendly to ide highlighting
  2. unflexible

wdvxdr1123 avatar Jan 12 '22 14:01 wdvxdr1123

我自己也替换了下,没想到这里有PR了。建议吧logrus的行号和代码文件整出来。 我的效果如下:

image

aohanhongzhi avatar May 19 '22 04:05 aohanhongzhi

优化了下,直接点击就可以跳转到打日志的位置,方便调试。 image

实现

import  nested "github.com/antonfisher/nested-logrus-formatter"
import  "github.com/sirupsen/logrus"


func init() {
	logrus.SetLevel(logrus.InfoLevel)
	logrus.SetReportCaller(true)

	logrus.SetFormatter(&nested.Formatter{
		HideKeys:    true,
		FieldsOrder: []string{"component", "category", "req"},
		CustomCallerFormatter: func(f *runtime.Frame) string {
			return fmt.Sprintf(" ( %s:%d )", f.File, f.Line)
		},
	})
}

aohanhongzhi avatar May 19 '22 08:05 aohanhongzhi