Skip to content

Commit b84cfe9

Browse files
committed
Add support for extended logging in DbConfig
Signed-off-by: bar haim <[email protected]>
1 parent 9efdd22 commit b84cfe9

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

platform/view/services/storage/driver/sql/postgres/test_utils.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ type ContainerConfig struct {
4747
}
4848

4949
type DbConfig struct {
50-
DBName string
51-
User string
52-
Pass string
53-
Host string
54-
Port int
50+
DBName string
51+
User string
52+
Pass string
53+
Host string
54+
Port int
55+
ExtendedLogging bool
5556
}
5657

5758
func (c *DbConfig) DataSource() string {
@@ -163,7 +164,7 @@ func startPostgresWithLogger(c ContainerConfig, t Logger, printLogs bool) (func(
163164
return nil, fmt.Errorf("can't start postgres: %s", err)
164165
}
165166
ctx := context.Background()
166-
resp, err := cli.ContainerCreate(ctx, &container.Config{
167+
containerConfig := &container.Config{
167168
Env: []string{
168169
"POSTGRES_DB=" + c.DBName,
169170
"POSTGRES_USER=" + c.User,
@@ -181,7 +182,28 @@ func startPostgresWithLogger(c ContainerConfig, t Logger, printLogs bool) (func(
181182
Timeout: time.Second,
182183
Retries: 10,
183184
},
184-
}, &container.HostConfig{
185+
}
186+
187+
// Add extended logging configuration if enabled
188+
if c.ExtendedLogging {
189+
containerConfig.Cmd = []string{
190+
"postgres",
191+
"-c", "log_destination=stderr",
192+
"-c", "logging_collector=on",
193+
"-c", "log_directory=pg_log",
194+
"-c", "log_filename=postgresql-%Y-%m-%d_%H%M%S.log",
195+
"-c", "log_min_duration_statement=0",
196+
"-c", "log_line_prefix=%t [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h ",
197+
"-c", "log_checkpoints=on",
198+
"-c", "log_connections=on",
199+
"-c", "log_disconnections=on",
200+
"-c", "log_lock_waits=on",
201+
"-c", "log_temp_files=0",
202+
"-c", "log_autovacuum_min_duration=0",
203+
}
204+
}
205+
206+
resp, err := cli.ContainerCreate(ctx, containerConfig, &container.HostConfig{
185207
PortBindings: nat.PortMap{
186208
nat.Port("5432/tcp"): []nat.PortBinding{
187209
{

0 commit comments

Comments
 (0)