Skip to content

Remove trailing newline from log calls#878

Merged
mfridman merged 1 commit intopressly:mainfrom
eest:log-no-trailing-newline
Jan 29, 2025
Merged

Remove trailing newline from log calls#878
mfridman merged 1 commit intopressly:mainfrom
eest:log-no-trailing-newline

Conversation

@eest
Copy link
Copy Markdown
Contributor

@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.
@mfridman mfridman merged commit 9c748e2 into pressly:main Jan 29, 2025
@eest eest deleted the log-no-trailing-newline branch January 29, 2025 14:35
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