Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: gin.StyleLogger, and the method functions and unit test codes of it. #2096

Closed
wants to merge 2 commits into from

Conversation

kerbalwzy
Copy link

Add a new struct type use for output the custom log information in gin.HanlderFunc with gin log style.

Unit testing result:
image

Preview of Actual Use Effect:
image

Usage demo code:

package main

import (
	"github.com/gin-gonic/gin"
	"log"
)

var GlobalGinStyleLogger *gin.StyleLogger

func init() {
	GlobalGinStyleLogger = gin.NewGinStyleLogger(nil, nil)
}

func ginStylLoggerDemo(c *gin.Context) {
	GlobalGinStyleLogger.Fprintln(c, 500, "<custom log information here>")
	c.Status(200)
}

func main() {
	router := gin.Default()
	router.GET("/example", ginStylLoggerDemo)
	err := router.Run(":8080")
	if nil != err {
		log.Fatal(err)
	}
}

@codecov
Copy link

codecov bot commented Oct 13, 2019

Codecov Report

Merging #2096 into master will decrease coverage by 0.41%.
The diff coverage is 76.74%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2096      +/-   ##
=========================================
- Coverage   98.92%   98.5%   -0.42%     
=========================================
  Files          40      40              
  Lines        2229    2272      +43     
=========================================
+ Hits         2205    2238      +33     
- Misses         12      18       +6     
- Partials       12      16       +4
Impacted Files Coverage Δ
logger.go 93.54% <76.74%> (-6.46%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7becac...6fcddbd. Read the comment docs.

@thinkerou
Copy link
Member

@kerbalwzy thanks a lot! please see #1677

@thinkerou thinkerou closed this Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants