Skip to content

Commit

Permalink
Log PostgreSQL and Redis connections
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Feb 13, 2024
1 parent be57c76 commit fd48d36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"

_ "github.com/lib/pq"
"github.com/rs/zerolog/log"
)

type DatabaseConfig struct {
Expand Down Expand Up @@ -54,7 +55,9 @@ func (cfg *DatabaseConfig) URL() *url.URL {
}

func (cfg *DatabaseConfig) Connect() (*sql.DB, error) {
return sql.Open("postgres", cfg.URL().String())
url := cfg.URL().String()
log.Info().Msgf("Connecting to PostgreSQL at %s:%d using database %s", cfg.Host, cfg.Port, cfg.Database)
return sql.Open("postgres", url)
}

func (cfg *DatabaseConfig) readEnv(prefix string) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/fpstore/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ var IndexPortFlag = cli.IntFlag{
}

func PrepareFingerprintCache(c *cli.Context) (FingerprintCache, error) {
host := c.String(RedisHostFlag.Name)
port := c.Int(RedisPortFlag.Name)
database := c.Int(RedisDatabaseFlag.Name)
log.Info().Msgf("Connecting to Redis at %s:%d using database %d", host, port, database)
return NewRedisFingerprintCache(&redis.Options{
Addr: net.JoinHostPort(c.String(RedisHostFlag.Name), strconv.Itoa(c.Int(RedisPortFlag.Name))),
Addr: net.JoinHostPort(host, strconv.Itoa(port)),
Password: c.String(RedisPasswordFlag.Name),
DB: c.Int(RedisDatabaseFlag.Name),
DB: database,
}), nil
}

Expand Down

0 comments on commit fd48d36

Please sign in to comment.