ensure that cfg.LogTo is properly closed on disconnect if its underlying type is a file

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2025-07-16 23:52:41 -04:00
parent bb5d6e6db3
commit 74f32a5352
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -20,7 +20,7 @@ const defaultKey = "default"
type Config struct {
DryRun bool // when true, queries will not run on the underlying database
LogLevel slog.Level // controls the level of information logged; defaults to slog.LevelInfo if not set
LogTo io.Writer // where to write log output to; defaults to os.Stdout
LogTo io.Writer // where to write log output to; defaults to os.Stdout
}
type Engine struct {
@ -121,6 +121,9 @@ func (e *Engine) logSql(msg, sql string) {
// Disconnect - closes and disposes of this Engine's connection pool.
func (e *Engine) Disconnect() {
e.conn.Close()
if asFile, ok := e.cfg.LogTo.(*os.File); ok {
_ = asFile.Close()
}
}
// Open - creates a new connection according to `connString`