10000 feat(logger):color latency by wsyqn6 · Pull Request #4146 · gin-gonic/gin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(logger):color latency #4146

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

feat(logger):color latency #4146

wants to merge 1 commit into from

Conversation

wsyqn6
Copy link
@wsyqn6 wsyqn6 commented Jan 23, 2025

add colored latency to log output based on latency thresholds

Summary

This PR introduces a new function LatencyColor in the logger middleware of the Gin framework. This function assigns colors to log output based on the request latency, improving the readability and visual identification of performance bottlenecks.

Motivation

The current logging system outputs latency as plain text, making it difficult to quickly identify performance issues at a glance. By adding color-coded latency information, developers can more easily distinguish between different latency levels, aiding in faster debugging and performance monitoring.

Changes

  1. Add LatencyColor Function: Implement a function that returns a color string based on the request latency.

image

@VILJkid
Copy link
VILJkid commented Feb 16, 2025

This will be a good addition, @wsyqn6!

@appleboy appleboy requested a review from Copilot May 21, 2025 00:27
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new function, LatencyColor, to color-code log output based on request latency, helping developers quickly identify performance issues.

  • Adds LatencyColor in logger.go to return ANSI color strings based on latency thresholds.
  • Adjusts latency formatting and expected outputs in logger_test.go for both colored and non-colored log outputs.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
logger.go Added LatencyColor function and modified latency truncation logic.
logger_test.go Updated test cases to match new latency truncation behavior and color assignment.
Comments suppressed due to low confidence (1)

logger_test.go:320

  • The helper variable name 'colorForLantency' appears to have a typo. Consider renaming it to 'colorForLatency' for clarity.
func TestColorForLatency(t *testing.T) {

@appleboy
Copy link
Member

@wsyqn6 Please rebase the master branch

@appleboy appleboy added this to the v1.11 milestone May 21, 2025
Copy link
codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 4 lines in your changes missing coverage. Please review.

Project coverage is 98.88%. Comparing base (3dc1cd6) to head (7f80bd3).
Report is 117 commits behind head on master.

Files with missing lines Patch % Lines
logger.go 85.71% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4146      +/-   ##
==========================================
- Coverage   99.21%   98.88%   -0.33%     
==========================================
  Files          42       44       +2     
  Lines        3182     3415     +233     
==========================================
+ Hits         3157     3377     +220     
- Misses         17       28      +11     
- Partials        8       10       +2     
Flag Coverage Δ
?
-tags "sonic avx" 98.87% <85.71%> (?)
-tags go_json 98.87% <85.71%> (?)
-tags nomsgpack 98.87% <85.71%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.22 98.88% <85.71%> (?)
go-1.23 98.88% <85.71%> (?)
macos-latest 98.88% <85.71%> (-0.33%) ⬇️
ubuntu-latest 98.88% <85.71%> (-0.33%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0