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

integrate Slog into logx #327

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

integrate Slog into logx #327

wants to merge 6 commits into from

Conversation

JiChenSSG
Copy link

@JiChenSSG JiChenSSG commented Sep 28, 2024

#325

Greptile Summary

This pull request integrates the new log/slog package from Go 1.21 into the logx module of the zero-contrib project, implementing a SlogWriter struct in logx/slogx/slog.go to adapt the logx.Writer interface for slog usage.

  • Replaced fmt.Sprint with fmt.Sprintf in logx/slogx/slog.go for consistent formatting across all types in log messages
  • Optimized toSlogFields function to create a single slice for all fields, improving efficiency
  • Implemented SlogWriter struct with methods for various log levels (Debug, Error, Info, etc.) using slog
  • Added NewSlogWriter function to create a new logx.Writer instance using slog.Handler

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings

logx/slogx/README.md Show resolved Hide resolved
logx/slogx/go.mod Show resolved Hide resolved
logx/slogx/go.mod Outdated Show resolved Hide resolved
logx/slogx/go.mod Show resolved Hide resolved
Comment on lines 58 to 65
func toSlogFields(fields ...logx.LogField) []interface{} {
slogFields := make([]interface{}, 0, len(fields) * 2)
for _, field := range fields {
slogFields = append(slogFields, field.Key, field.Value)
}

return slogFields
}
Copy link

Choose a reason for hiding this comment

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

style: toSlogFields creates a new slice for each call. Consider using a pool for better performance in high-volume logging scenarios.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

logx/slogx/go.mod Show resolved Hide resolved
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

logx/slogx/slog.go Outdated Show resolved Hide resolved
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

LGTM

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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.

1 participant