Skip to content

Conversation

@yhakbar
Copy link
Collaborator

@yhakbar yhakbar commented Mar 1, 2025

Closes #9

}
func NewLogger(filename string) *Logger {
if filename == "" {
handler := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
Copy link
Contributor

Choose a reason for hiding this comment

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

imho the default log format is better for human readability on stderr, while JSON makes sense for file output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's a lot more convenient to use file based logger when working with the LS, but I made the switch in #12 to make that happen.

}

// Debug logs a debug message
func (l *Logger) Debug(msg string, args ...interface{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit rusty but these methods look like noops since you are embedding *slog.Logger. Do you need them?

Copy link
Collaborator Author

@yhakbar yhakbar Mar 3, 2025

Choose a reason for hiding this comment

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

No. Weekend brain. That was part of an incomplete process of setting up an interface, then explicitly implementing the interface for the logger so that it can be easily replaced in the future, etc.

I adjusted that in #12

// Check if the current line is the one we're looking for
if scannedLines == int(position.Line) {
l.Debugf("Hit line %d: %s", position.Line, line)
l.Debug(
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that you chose to use formatting instead of structured logging while using Zap and had to switch over for slog. The structured logging does add quite a bit of verbosity. Curious if you considered writing Debugf, Infof, etc functions on the log wrapper to do formatting instead of key/value pairs? Then I think most of the other changes would be unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ya. The reason why structured logging was preferred here is that we're going to be logging JSON events between the server and client, so I figured it would be most convenient to log with the JSON logger.

@yhakbar yhakbar merged commit 7b38151 into main Mar 3, 2025
4 of 5 checks passed
@yhakbar yhakbar deleted the 9/switching-to-slog branch March 3, 2025 13:28
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.

Switch to new logger (slog)

2 participants