Skip to content

Commit 1c6b6f2

Browse files
committed
debug logging
1 parent 85f6c37 commit 1c6b6f2

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

pkg/config/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"fmt"
45
"log"
56
"net/url"
67
"strconv"
@@ -20,11 +21,26 @@ type cfg struct {
2021
CloudProvider string `env:"POSTGRES_CLOUD_PROVIDER"`
2122
AnnotationFilter string `env:"POSTGRES_INSTANCE"`
2223
KeepSecretName bool `env:"KEEP_SECRET_NAME"`
24+
DebugLog bool `env:"DEBUG_LOG"`
2325
}
2426

2527
var doOnce sync.Once
28+
2629
var config *cfg
2730

31+
func (c *cfg) AsLog() interface{} {
32+
return map[string]string{
33+
"pg.host": c.PostgresHost,
34+
"pg.user": c.PostgresUser,
35+
"pg.port": fmt.Sprint(c.PostgresPort),
36+
"pg.uri": c.PostgresUriArgs,
37+
"pg.defaultDB": c.PostgresDefaultDb,
38+
"pg.cloudProvider": c.CloudProvider,
39+
"pg.annotationFilter": c.AnnotationFilter,
40+
"pg.keepSecretName": fmt.Sprint(c.KeepSecretName),
41+
}
42+
}
43+
2844
func Get() *cfg {
2945
doOnce.Do(func() {
3046
config = &cfg{}

pkg/controller/postgres/postgres_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ func Add(mgr manager.Manager) error {
3434
// newReconciler returns a new reconcile.Reconciler
3535
func newReconciler(mgr manager.Manager) reconcile.Reconciler {
3636
c := config.Get()
37+
if c.DebugLog {
38+
log.WithName("postgres").WithValues(c.AsLog()).Info("Debug")
39+
}
3740
pg, err := postgres.NewPG(
38-
fmt.Sprintf("%s:%d", c.PostgresHost, c.PostgresPort),
41+
c.PostgresHost,
3942
c.PostgresUser,
4043
c.PostgresPass,
4144
c.PostgresPort,

pkg/controller/postgresuser/postgresuser_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ func Add(mgr manager.Manager) error {
4444
// newReconciler returns a new reconcile.Reconciler
4545
func newReconciler(mgr manager.Manager) reconcile.Reconciler {
4646
c := config.Get()
47+
if c.DebugLog {
48+
log.WithName("postgresuser").WithValues(c.AsLog()).Info("Debug")
49+
}
4750
pg, err := postgres.NewPG(
48-
fmt.Sprintf("%s:%d", c.PostgresHost, c.PostgresPort),
51+
c.PostgresHost,
4952
c.PostgresUser,
5053
c.PostgresPass,
5154
c.PostgresPort,

0 commit comments

Comments
 (0)