现在的错误信息输出到控制台,要怎么写入到文件呢 用的最新的v2版本
// logrus
Log = logrus.New()
//Log.Max
Log.Out = ioutil.Discard
Log.SetReportCaller(true)
Log.SetFormatter(&logrus.JSONFormatter{})
pathMap := lfshook.PathMap{
logrus.InfoLevel: Path + "/info.log",
logrus.ErrorLevel: Path + "/error.log",
logrus.DebugLevel: Path + "/debug.log",
}
Log.SetLevel(logrus.DebugLevel)
//// 添加钩子,用于将 error 级别的日志消息发送到接口中
//// 创建 LfsHook 钩子
Log.AddHook(lfshook.NewHook(
pathMap,
&logrus.JSONFormatter{},
))
newLogger := logger.New(
Log, // io writer(日志输出的目标,前缀和日志包含的内容——译者注)
logger.Config{
SlowThreshold: time.Second, // 慢 SQL 阈值
LogLevel: logger.Error, // 日志级别
IgnoreRecordNotFoundError: true, // 忽略ErrRecordNotFound(记录未找到)错误
Colorful: false, // 禁用彩色打印
},
)
Db, err = gorm.Open(mysql.Open(conn), &gorm.Config{
QueryFields: true,
DisableForeignKeyConstraintWhenMigrating: true,
Logger: newLogger,
//DisableDatetimePrecision: true,
})
下面这条语句会报错,但是为什么输出到控制台了.不写入日志呢?
DB.Debug().Where("id = 1").Update("status", 1)
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨