ensure that cfg.LogTo
is properly closed on disconnect if its underlying type is a file
This commit is contained in:
parent
bb5d6e6db3
commit
74f32a5352
@ -20,7 +20,7 @@ const defaultKey = "default"
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
DryRun bool // when true, queries will not run on the underlying database
|
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
|
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 {
|
type Engine struct {
|
||||||
@ -121,6 +121,9 @@ func (e *Engine) logSql(msg, sql string) {
|
|||||||
// Disconnect - closes and disposes of this Engine's connection pool.
|
// Disconnect - closes and disposes of this Engine's connection pool.
|
||||||
func (e *Engine) Disconnect() {
|
func (e *Engine) Disconnect() {
|
||||||
e.conn.Close()
|
e.conn.Close()
|
||||||
|
if asFile, ok := e.cfg.LogTo.(*os.File); ok {
|
||||||
|
_ = asFile.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open - creates a new connection according to `connString`
|
// Open - creates a new connection according to `connString`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user