From 74f32a53521e4059ea3800e1bc11c43d4b4bd034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Wed, 16 Jul 2025 23:52:41 -0400 Subject: [PATCH] ensure that `cfg.LogTo` is properly closed on disconnect if its underlying type is a file --- diamond.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/diamond.go b/diamond.go index 2ed14d7..6b5017a 100644 --- a/diamond.go +++ b/diamond.go @@ -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`