Skip to content

Commit

Permalink
Add LogLevel to pq driver
Browse files Browse the repository at this point in the history
  • Loading branch information
perrito666 committed Aug 22, 2018
1 parent c7b663a commit b1dd52c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions db/postgres/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (c *Connector) Open(ci *connection.Information) (connection.DB, error) {
return nil, errors.Wrap(err, "parsing connection string")
}
if ci != nil {
llevel, llevelErr := pgx.LogLevelFromString(string(ci.LogLevel))
if llevelErr != nil {
llevel = pgx.LogLevelError
}
config.ConnConfig = csconfig.Merge(pgx.ConnConfig{
Host: ci.Host,
Port: ci.Port,
Expand All @@ -92,6 +96,7 @@ func (c *Connector) Open(ci *connection.Information) (connection.DB, error) {
UseFallbackTLS: ci.UseFallbackTLS,
FallbackTLSConfig: ci.FallbackTLSConfig,
Logger: logging.NewPgxLogAdapter(ci.Logger),
LogLevel: int(llevel),
})
} else {
defaultLogger := log.New(os.Stdout, "logger: ", log.Lshortfile)
Expand Down
10 changes: 10 additions & 0 deletions db/postgrespq/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func (c *Connector) Open(ci *connection.Information) (connection.DB, error) {
var config pgx.ConnPoolConfig
var conLogger logging.Logger
if ci != nil {
llevel, llevelErr := pgx.LogLevelFromString(string(ci.LogLevel))
if llevelErr != nil {
llevel = pgx.LogLevelError
}
conLogger = ci.Logger
config = pgx.ConnPoolConfig{
ConnConfig: pgx.ConnConfig{
Expand All @@ -63,6 +67,7 @@ func (c *Connector) Open(ci *connection.Information) (connection.DB, error) {
UseFallbackTLS: ci.UseFallbackTLS,
FallbackTLSConfig: ci.FallbackTLSConfig,
Logger: logging.NewPgxLogAdapter(conLogger),
LogLevel: int(llevel),
},
MaxConnections: ci.MaxConnPoolConns,
}
Expand All @@ -76,6 +81,10 @@ func (c *Connector) Open(ci *connection.Information) (connection.DB, error) {
return nil, errors.Wrap(err, "parsing connection string")
}
if ci != nil {
llevel, llevelErr := pgx.LogLevelFromString(string(ci.LogLevel))
if llevelErr != nil {
llevel = pgx.LogLevelError
}
config.ConnConfig = csconfig.Merge(pgx.ConnConfig{
Host: ci.Host,
Port: ci.Port,
Expand All @@ -87,6 +96,7 @@ func (c *Connector) Open(ci *connection.Information) (connection.DB, error) {
UseFallbackTLS: ci.UseFallbackTLS,
FallbackTLSConfig: ci.FallbackTLSConfig,
Logger: logging.NewPgxLogAdapter(ci.Logger),
LogLevel: int(llevel),
})
} else {
defaultLogger := log.New(os.Stdout, "logger: ", log.Lshortfile)
Expand Down

0 comments on commit b1dd52c

Please sign in to comment.