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

Remove trailing newline from log calls #878

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

Conversation

eest
Copy link

@eest eest commented Dec 19, 2024

This way there is no need to clean up a newline when implementing your own goose.Logger. The standard log package being used by default will add a newline if it is not there.

For reference, I noticed this when trying to implement a goose.Logger using https://github.com/rs/zerolog, looking like so:

type gooseLogger struct {
	logger zerolog.Logger
}

func (gl gooseLogger) Fatalf(format string, v ...interface{}) {
	gl.logger.Fatal().Msgf(format, v...)
}

func (gl gooseLogger) Printf(format string, v ...interface{}) {
	gl.logger.Info().Msgf(format, v...)
}

Where the resulting log message ended up like this (note the trailing newline in message):

{"level":"info", "time":"2024-12-19T08:36:40+01:00","caller":"migrations.go:25","message":"goose: no migrations to run. current version: 1\n"}

This way there is no need to clean up a newline when implementing your
own goose.Logger. The standard log package being used by default will
add a newline if it is not there.
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