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

Add slog support to goose provider #836

Closed
wants to merge 1 commit into from
Closed

Add slog support to goose provider #836

wants to merge 1 commit into from

Conversation

mfridman
Copy link
Collaborator

This PR enable callers to pass a *slog.Logger logger to goose provider. Example:

logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
_, err = goose.NewProvider(goose.DialectSQLite3, db, fsys,
	goose.WithLogger(logger),
)

And internally goose will invoke the structured logger:

logger.Info("applied migration",
	slog.String("source", filepath.Base(m.Source)),
	slog.Any("direction", direction),
	slog.Any("duration", result.Duration),
	slog.Bool("empty", result.Empty),
)

By default if WithVerbose(true) is enabled but no logger is supplied, goose will use an internal text logger:

time="2024-10-14 13:07:30" level=INFO msg="applied migration" logger=goose source=00001_users_table.sql direction=up duration=1.174375ms empty=false

An alternative implementation is to using the existing goose.Logger interface, but I worry this may corner goose into a corner.

@mfridman
Copy link
Collaborator Author

Closing for now. #833 (comment)

@mfridman mfridman closed this Oct 19, 2024
@mfridman mfridman deleted the mf/slog branch October 19, 2024 21:06
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