Skip to content

Commit

Permalink
fix: logger with config
Browse files Browse the repository at this point in the history
Signed-off-by: Eray Ates <[email protected]>
  • Loading branch information
rytsh committed Jun 17, 2024
1 parent 9c2ea5a commit 64f1978
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"os"
"regexp"
"strings"

"github.com/worldline-go/logz"
)

// Config provides a way to specify some optional configuration.
Expand Down Expand Up @@ -39,6 +41,8 @@ type Config struct {

// Values for expand function in migration files.
Values map[string]string

Logger logz.Adapter
}

// SetDefaults will update missing values with default ones(if any).
Expand Down
11 changes: 10 additions & 1 deletion igmigrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/worldline-go/logz"
)

Expand Down Expand Up @@ -114,7 +115,15 @@ func MigrateInTx(ctx context.Context, tx Transaction, cnf *Config) (*MigrateResu
migration := Migrator{
Cnf: cnf,
Tx: tx,
Logger: logz.AdapterKV{Log: *zerolog.Ctx(ctx)},
Logger: cnf.Logger,
}

if migration.Logger == nil {
if zlog := zerolog.Ctx(ctx); zlog != nil {
migration.Logger = logz.AdapterKV{Log: *zlog, Caller: true}
} else {
migration.Logger = logz.AdapterKV{Log: log.Logger, Caller: true}
}
}

if err := migration.SetSchema(ctx); err != nil {
Expand Down

0 comments on commit 64f1978

Please sign in to comment.