Some logging refactoring.

Fixes #14.
This commit is contained in:
2020-02-29 23:30:44 +05:00
parent 5f58741159
commit 825fd724ff
9 changed files with 43 additions and 47 deletions

View File

@@ -165,11 +165,11 @@ func (db *Database) Initialize() {
}
dbConnString := fmt.Sprintf("postgres://%s@%s:%s/%s?connect_timeout=10&fallback_application_name=fastpastebin&sslmode=disable", userpass, c.Config.Database.Address, c.Config.Database.Port, c.Config.Database.Database)
c.Logger.Debug().Msgf("Database connection string: %s", dbConnString)
c.Logger.Debug().Str("DSN", dbConnString).Msg("Database connection string composed")
dbConn, err := sqlx.Connect("postgres", dbConnString)
if err != nil {
c.Logger.Error().Msgf("Failed to connect to database: %s", err.Error())
c.Logger.Error().Err(err).Msg("Failed to connect to database")
return
}
@@ -204,7 +204,7 @@ func (db *Database) Shutdown() {
if db.db != nil {
err := db.db.Close()
if err != nil {
c.Logger.Error().Msgf("Failed to close database connection: %s", err.Error())
c.Logger.Error().Err(err).Msg("Failed to close database connection")
}
}
}