[golang] logrus的简单封装

栏目: Go · 发布时间: 6年前

内容简介:在大型项目中,使用

在大型项目中,使用 logrus 进行日志打印,如不加一些如 [usecase.CreateUser] 前缀,将会很难定位到打印日志的代码位置。故 liamylian/logrus-ext 借鉴了 python 的logging模块,对 logrus 进行了简单封装。从而可以在日志中打印当前的模块名和调用函数名。

var log = Get("usecase", &Option{WithFunc: true})

// 输出:
//   time="2019-04-18T15:36:37+08:00" level=error msg="query task error: id=1" error="too many connection" 
//   func="github.com/liamylian/logrus-ext.(*db).QueryTask" name=usecase
err := errors.New("too many connection")
log.WithError(err).Errorf("query task error: id=%d", id)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Concepts, Techniques, and Models of Computer Programming

Concepts, Techniques, and Models of Computer Programming

Peter Van Roy、Seif Haridi / The MIT Press / 2004-2-20 / USD 78.00

This innovative text presents computer programming as a unified discipline in a way that is both practical and scientifically sound. The book focuses on techniques of lasting value and explains them p......一起来看看 《Concepts, Techniques, and Models of Computer Programming》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

html转js在线工具
html转js在线工具

html转js在线工具