当前位置:网站首页>Go: Gin custom log output format
Go: Gin custom log output format
2022-07-25 12:50:00 【It workers】
In this paper, the experiment gin frame Custom log format
Code :
package main
import (
"fmt"
"time"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.New()
// LoggerWithFormatter middleware will write the logs to gin.DefaultWrite
// By default gin.DefaultWriter = os.Stdout
router.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
// your custom format
return fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
param.ClientIP,
param.TimeStamp.Format(time.RFC1123),
param.Method,
param.Path,
param.Request.Proto,
param.StatusCode,
param.Latency,
param.Request.UserAgent(),
param.ErrorMessage,
)
}))
router.Use(gin.Recovery())
router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
router.Run(":8080")
}Running results :
[GIN-debug] GET /ping --> main.main.func2 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8080
::1 - [Thu, 05 July 2022 19:28:05 CST] "GET / HTTP/1.1 404 5.113µs "curl/7.54.0" "
::1 - [Thu, 05 July 2022 19:28:05 CST] "GET / HTTP/1.1 404 1.029µs "curl/7.54.0" "
::1 - [Thu, 05 July 2022 19:28:06 CST] "GET / HTTP/1.1 404 1.19µs "curl/7.54.0" "
::1 - [Thu, 05 July 2022 19:28:10 CST] "GET / HTTP/1.1 404 1.565µs "curl/7.54.0" "
::1 - [Thu, 05 July 2022 19:29:08 CST] "GET /ping HTTP/1.1 200 157.996µs "curl/7.54.0" "
::1 - [Thu, 05 July 2022 19:29:09 CST] "GET /ping HTTP/1.1 200 68.985µs "curl/7.54.0" "
边栏推荐
- 卷积核越大性能越强?一文解读RepLKNet模型
- 基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
- 阿里云技术专家秦隆:可靠性保障必备——云上如何进行混沌工程?
- 零基础学习CANoe Panel(12)—— 进度条(Progress Bar)
- Jenkins configuration pipeline
- Synergetic process
- mysql有 flush privileges 吗
- 2022 Henan Mengxin League game (3): Henan University I - Travel
- Introduction to the scratch crawler framework
- Pytorch environment configuration and basic knowledge
猜你喜欢

A hard journey

Pytorch advanced training skills

基于JEECG制作一个通用的级联字典选择控件-DictCascadeUniversal

Kyligence was selected into Gartner 2022 data management technology maturity curve report
![[advanced C language] dynamic memory management](/img/b7/6586b35500eb8f39a3ea8c125fb572.png)
[advanced C language] dynamic memory management

Azure Devops (XIV) use azure's private nuget warehouse

More accurate and efficient segmentation of organs-at-risk in radiotherapy with Convolutional Neural

【AI4Code】《GraphCodeBERT: Pre-Training Code Representations With DataFlow》 ICLR 2021

Build a series of vision transformer practices, and finally meet, Timm library!

LeetCode 0133. 克隆图
随机推荐
Deep learning MEMC framing paper list
【4】 Layout view and layout toolbar usage
JS 中根据数组内元素的属性进行排序
What does the software testing process include? What are the test methods?
【AI4Code】《CodeBERT: A Pre-Trained Model for Programming and Natural Languages》 EMNLP 2020
A hard journey
[problem solving] org.apache.ibatis.exceptions PersistenceException: Error building SqlSession. 1-byte word of UTF-8 sequence
Keeping MySQL highly available
Cmake learning notes (II) generation and use of Library
力扣 83双周赛T4 6131.不可能得到的最短骰子序列、303 周赛T4 6127.优质数对的数目
Selenium uses -- XPath and analog input and analog click collaboration
Detailed explanation of flex box
JS 将伪数组转换成数组
mysql实现一张表数据插入另一张表
Is the securities account opened by qiniu safe? How to open an account
【7】 Layer display and annotation
485通讯( 详解 )
2022 Henan Mengxin League game (3): Henan University I - Travel
【5】 Page and print settings
想要做好软件测试,可以先了解AST、SCA和渗透测试