From b1dd52cbe63afb97e3c48795412e782e0c4f5eb2 Mon Sep 17 00:00:00 2001 From: Horacio Duran Date: Wed, 22 Aug 2018 12:59:26 +0100 Subject: [PATCH] Add LogLevel to pq driver --- db/postgres/connection.go | 5 +++++ db/postgrespq/connection.go | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/db/postgres/connection.go b/db/postgres/connection.go index e56a910..f03c9de 100644 --- a/db/postgres/connection.go +++ b/db/postgres/connection.go @@ -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, @@ -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) diff --git a/db/postgrespq/connection.go b/db/postgrespq/connection.go index abaf35f..193513d 100644 --- a/db/postgrespq/connection.go +++ b/db/postgrespq/connection.go @@ -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{ @@ -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, } @@ -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, @@ -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)