Skip to content

Add slog support to goose provider#836

Closed
mfridman wants to merge 1 commit intomasterfrom
mf/slog
Closed

Add slog support to goose provider#836
mfridman wants to merge 1 commit intomasterfrom
mf/slog

Conversation

@mfridman
Copy link
Copy Markdown
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
Copy Markdown
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