package
1.0.8
Repository: https://github.com/csystem/gcuu.git
Documentation: pkg.go.dev

# README

各种自制 Gin 中间件

logger.go

logrus 是结构化的,与 golang 标准库完全兼容的 golang 日志打印框架。支持 Filed 和 HOOK 机制,自带 text 和 json 两种日志输出格式。

logrus 自带两种格式 logrus.JSONFormatter{} 和 logrus.TextFormatter{}。

logrus 提供 6 档日志级别,分别是:

  • PanicLevel
  • FatalLevel - 网站挂了,或者极度不正常
  • ErrorLevel - 跟遇到的用户说对不起,可能有bug
  • WarnLevel - 记录一下,某事又发生了
  • InfoLevel - 提示一切正常
  • DebugLevel - 没问题,就看看堆栈

middleware 的使用方法

r := gin.Default()                  // 默认启动方式,包含 Logger、Recovery 中间件
r.Use(middleware.LoggerToFile(app)) // 初始化日
log.Debug("Useful debugging information.")
log.Info("Something noteworthy happened!")
log.Warn("You should probably take a look at this.")
log.Error("Something failed but I'm not quitting.")
log.Fatal("Bye.") // 随后会触发os.Exit(1)
log.Panic("I'm bailing.") // 随后会触发panic()

[GIN] 2018/05/30 - 19:21:17 | 404 |     114.656µs |             ::1 |  GET     /comment/view/99999
[GIN] 2018/05/30 - 19:21:20 | 200 |     1.82468ms |             ::1 |  GET     /comment/view/00001

参考

# Functions

Logger gin 日志输出到文件.