gin icon indicating copy to clipboard operation
gin copied to clipboard

feat(logger):color latency

Open wsyqn6 opened this issue 11 months ago • 3 comments

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

wsyqn6 avatar Jan 23 '25 07:01 wsyqn6

This will be a good addition, @wsyqn6!

VILJkid avatar Feb 16 '25 23:02 VILJkid

@wsyqn6 Please rebase the master branch

appleboy avatar May 21 '25 00:05 appleboy

Codecov Report

:x: Patch coverage is 85.71429% with 4 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 98.81%. Comparing base (3dc1cd6) to head (8eb54b8). :warning: Report is 184 commits behind head on master.

Files with missing lines Patch % Lines
logger.go 85.71% 4 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4146      +/-   ##
==========================================
- Coverage   99.21%   98.81%   -0.41%     
==========================================
  Files          42       44       +2     
  Lines        3182     3456     +274     
==========================================
+ Hits         3157     3415     +258     
- Misses         17       30      +13     
- Partials        8       11       +3     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 98.74% <85.71%> (?)
-tags go_json 98.74% <85.71%> (?)
-tags nomsgpack 98.79% <85.71%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.23 98.81% <85.71%> (?)
go-1.24 98.81% <85.71%> (?)
macos-latest 98.81% <85.71%> (-0.41%) :arrow_down:
ubuntu-latest 98.81% <85.71%> (-0.41%) :arrow_down:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar May 21 '25 00:05 codecov[bot]

Please rebase the master branch

appleboy avatar Jun 18 '25 14:06 appleboy

Please rebase the master branch

I've rebased this PR onto the latest master branch. The changes are now up to date and ready for review. Thanks for your patience!

wsyqn6 avatar Jun 19 '25 02:06 wsyqn6