Skip to content

Log levels change #7414

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 3 commits into
base: master
Choose a base branch
from
Open

Log levels change #7414

wants to merge 3 commits into from

Conversation

hertzcodes
Copy link

@hertzcodes hertzcodes commented Apr 10, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Almost every logger's log levels is descending so i decided to change Gorm's levels too since I had problems configuring slog with it.

User Case Description

@jinzhu jinzhu requested a review from Copilot May 22, 2025 03:17
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 changes the log level ordering to follow a descending scale so that lower numerical values represent more verbose logging. Key changes include:

  • Explicit log level constant assignments (Silent = 12, Error = 8, Warn = 4, Info = 0).
  • Reversal of log condition comparisons in the Info, Warn, Error, and Trace methods.
  • Adjustments in the Trace method to correctly gate logging based on the new descending log level order.

@@ -135,21 +135,21 @@ func (l *logger) LogMode(level LogLevel) Interface {

// Info print info
func (l *logger) Info(ctx context.Context, msg string, data ...interface{}) {
if l.LogLevel >= Info {
if l.LogLevel <= Info {
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

Consider adding a comment here to clarify that the reversed comparison (<=) is used because lower numerical values indicate higher verbosity.

Copilot uses AI. Check for mistakes.

@@ -158,28 +158,28 @@ func (l *logger) Error(ctx context.Context, msg string, data ...interface{}) {
//
//nolint:cyclop
func (l *logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) {
if l.LogLevel <= Silent {
if l.LogLevel >= Silent {
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

Consider adding a comment to explain that logging is skipped when the logger's level is set to Silent or higher, following the new descending order.

Copilot uses AI. Check for mistakes.

@@ -36,13 +36,13 @@ type LogLevel int

const (
// Silent silent log level
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change it to a fixed number instead of just reordering them?

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.

2 participants