Skip to content

Commit 127e38f

Browse files
committed
Enhance embedded Postgres configuration and logging setup
Added customizable startup parameters and log directory support for embedded Postgres. Introduced runtime configuration checks and warnings for required restarts when settings change to improve usability and debugging.
1 parent a1d6d53 commit 127e38f

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Config struct {
1515
port uint32
1616
useUnixSocket bool
1717
unixSocketDirectory string
18+
logDirectory string
1819
database string
1920
username string
2021
password string
@@ -84,6 +85,13 @@ func (c Config) WithUnixSocketDirectory(dir string) Config {
8485
return c
8586
}
8687

88+
// LogDirectory sets the directory where the temporary embedded Postgres capture
89+
// file is created before its content is forwarded to the configured logger.
90+
func (c Config) LogDirectory(dir string) Config {
91+
c.logDirectory = dir
92+
return c
93+
}
94+
8795
// Database sets the database name that will be created.
8896
func (c Config) Database(database string) Config {
8997
c.database = database

embedded_postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (ep *EmbeddedPostgres) Start() error {
7777
}
7878
}
7979

80-
logger, err := newSyncedLogger("", ep.config.logger)
80+
logger, err := newSyncedLogger(ep.config.logDirectory, ep.config.logger)
8181
if err != nil {
8282
return errors.New("unable to create logger")
8383
}

logging.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ type syncedLogger struct {
1515
}
1616

1717
func newSyncedLogger(dir string, logger io.Writer) (*syncedLogger, error) {
18+
if dir != "" {
19+
if err := os.MkdirAll(dir, 0o755); err != nil {
20+
return nil, err
21+
}
22+
}
1823
file, err := os.CreateTemp(dir, "embedded_postgres_log")
1924
if err != nil {
2025
return nil, err

0 commit comments

Comments
 (0)