Skip to content

Commit

Permalink
[CR] Take logger *only* from context
Browse files Browse the repository at this point in the history
  • Loading branch information
arielshaqed committed Aug 26, 2020
1 parent 8f91f92 commit 599772a
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions db/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Database interface {
Metadata() (map[string]string, error)
Stats() sql.DBStats
WithContext(ctx context.Context) Database
WithLogger(logger logging.Logger) Database
}

type QueryOptions struct {
Expand All @@ -47,7 +46,7 @@ func (d *SqlxDatabase) getLogger() logging.Logger {
if d.queryOptions != nil {
return d.queryOptions.logger
}
return logging.Default().WithContext(d.getContext())
return logging.Default()
}

func (d *SqlxDatabase) getContext() context.Context {
Expand All @@ -61,22 +60,12 @@ func (d *SqlxDatabase) WithContext(ctx context.Context) Database {
return &SqlxDatabase{
db: d.db,
queryOptions: &QueryOptions{
logger: d.getLogger(),
logger: logging.Default().WithContext(ctx),
ctx: ctx,
},
}
}

func (d *SqlxDatabase) WithLogger(logger logging.Logger) Database {
return &SqlxDatabase{
db: d.db,
queryOptions: &QueryOptions{
logger: logger,
ctx: d.getContext(),
},
}
}

func (d *SqlxDatabase) Close() error {
return d.db.Close()
}
Expand Down

0 comments on commit 599772a

Please sign in to comment.