Skip to content

Commit 05d373a

Browse files
committed
Improve logging output for database auto init
1 parent d80687f commit 05d373a

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

sync/database_mysql.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ func (database *DatabaseMysql) init() {
2929
if val, ok := containerEnv["MYSQL_ROOT_PASSWORD"]; ok {
3030
// get root pass from env
3131
if database.Local.User == "" && database.Local.Password == "" {
32-
fmt.Println(" -> local: using mysql root account (from MYSQL_ROOT_PASSWORD)")
32+
fmt.Println(" -> local: using mysql root account (from env:MYSQL_ROOT_PASSWORD)")
3333
database.Local.User = "root"
3434
database.Local.Password = val
3535
}
3636
} else if val, ok := containerEnv["MYSQL_ALLOW_EMPTY_PASSWORD"]; ok {
3737
// get root without password from env
3838
if val == "yes" && database.Local.User == "" {
39-
fmt.Println(" -> local: using mysql root account (from MYSQL_ALLOW_EMPTY_PASSWORD)")
39+
fmt.Println(" -> local: using mysql root account (from env:MYSQL_ALLOW_EMPTY_PASSWORD)")
4040
database.Local.User = "root"
4141
database.Local.Password = ""
4242
}
4343
} else if user, ok := containerEnv["MYSQL_USER"]; ok {
4444
if pass, ok := containerEnv["MYSQL_PASSWORD"]; ok {
4545
if database.Local.User == "" && database.Local.Password == "" {
46-
fmt.Println(" -> local: using mysql user account (from MYSQL_USER and MYSQL_PASSWORD)")
46+
fmt.Println(fmt.Sprintf(" -> local: using mysql user account \"%s\" (from env:MYSQL_USER and env:MYSQL_PASSWORD)", user))
4747
database.Local.User = user
4848
database.Local.Password = pass
4949
}
@@ -53,9 +53,9 @@ func (database *DatabaseMysql) init() {
5353

5454
// get schema from env
5555
if database.Local.Schema == "" {
56-
if val, ok := containerEnv["MYSQL_DATABASE"]; ok {
57-
fmt.Println(" -> local: using mysql schema (from MYSQL_DATABASE)")
58-
database.Local.Schema = val
56+
if schema, ok := containerEnv["MYSQL_DATABASE"]; ok {
57+
fmt.Println(fmt.Sprintf(" -> local: using mysql schema \"%s\" (from env:MYSQL_DATABASE)", schema))
58+
database.Local.Schema = schema
5959
}
6060
}
6161
}
@@ -79,21 +79,21 @@ func (database *DatabaseMysql) init() {
7979
if val, ok := containerEnv["MYSQL_ROOT_PASSWORD"]; ok {
8080
// get root pass from env
8181
if database.User == "" && database.Password == "" {
82-
fmt.Println(" -> remote: using mysql root account (from MYSQL_ROOT_PASSWORD)")
82+
fmt.Println(" -> remote: using mysql root account (from env:MYSQL_ROOT_PASSWORD)")
8383
database.User = "root"
8484
database.Password = val
8585
}
8686
} else if val, ok := containerEnv["MYSQL_ALLOW_EMPTY_PASSWORD"]; ok {
8787
// get root without password from env
8888
if val == "yes" && database.User == "" {
89-
fmt.Println(" -> remote: using mysql root account (from MYSQL_ALLOW_EMPTY_PASSWORD)")
89+
fmt.Println(" -> remote: using mysql root account (from env:MYSQL_ALLOW_EMPTY_PASSWORD)")
9090
database.User = "root"
9191
database.Password = ""
9292
}
9393
} else if user, ok := containerEnv["MYSQL_USER"]; ok {
9494
if pass, ok := containerEnv["MYSQL_PASSWORD"]; ok {
9595
if database.User == "" && database.Password == "" {
96-
fmt.Println(" -> remote: using mysql user account (from MYSQL_USER and MYSQL_PASSWORD)")
96+
fmt.Println(fmt.Sprintf(" -> remote: using mysql user account \"%s\" (from env:MYSQL_USER and env:MYSQL_PASSWORD)", user))
9797
database.User = user
9898
database.Password = pass
9999
}
@@ -103,9 +103,9 @@ func (database *DatabaseMysql) init() {
103103

104104
// get schema from env
105105
if database.Schema == "" {
106-
if val, ok := containerEnv["MYSQL_DATABASE"]; ok {
107-
fmt.Println(" -> remote: using mysql schema (from MYSQL_DATABASE)")
108-
database.Schema = val
106+
if schema, ok := containerEnv["MYSQL_DATABASE"]; ok {
107+
fmt.Println(fmt.Sprintf(" -> remote: using mysql schema \"%s\" (from env:MYSQL_DATABASE)", schema))
108+
database.Schema = schema
109109
}
110110
}
111111
}

sync/database_postgres.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ func (database *DatabasePostgres) init() {
3030
// get superuser pass from env
3131
if pass, ok := containerEnv["POSTGRES_PASSWORD"]; ok {
3232
if user, ok := containerEnv["POSTGRES_USER"]; ok {
33-
fmt.Println(" -> local: using postgres superadmin account (from POSTGRES_USER and POSTGRES_PASSWORD)")
33+
fmt.Println(fmt.Sprintf(" -> local: using postgres superadmin account \"%s\" (from env:POSTGRES_USER and env:POSTGRES_PASSWORD)", user))
3434
database.Local.User = user
3535
database.Local.Password = pass
3636
} else {
37-
fmt.Println(" -> local: using postgres superadmin account (from POSTGRES_PASSWORD)")
37+
fmt.Println(" -> local: using postgres superadmin account \"postgres\" (from env:POSTGRES_PASSWORD)")
3838
// only password available
3939
database.Local.User = "postgres"
4040
database.Local.Password = pass
@@ -44,9 +44,9 @@ func (database *DatabasePostgres) init() {
4444

4545
// get schema from env
4646
if database.Local.Schema == "" {
47-
if val, ok := containerEnv["POSTGRES_DB"]; ok {
48-
fmt.Println(" -> local: using postgres schema (from POSTGRES_DB)")
49-
database.Local.Schema = val
47+
if schema, ok := containerEnv["POSTGRES_DB"]; ok {
48+
fmt.Println(fmt.Sprintf(" -> remote: using postgres schema \"%s\" (from env:POSTGRES_DB)", schema))
49+
database.Local.Schema = schema
5050
}
5151
}
5252
}
@@ -70,11 +70,11 @@ func (database *DatabasePostgres) init() {
7070
// get superuser pass from env
7171
if pass, ok := containerEnv["POSTGRES_PASSWORD"]; ok {
7272
if user, ok := containerEnv["POSTGRES_USER"]; ok {
73-
fmt.Println(" -> remote: using postgres superadmin account (from POSTGRES_USER and POSTGRES_PASSWORD)")
73+
fmt.Println(fmt.Sprintf(" -> remote: using postgres superadmin account \"%s\" (from env:POSTGRES_USER and env:POSTGRES_PASSWORD)", user))
7474
database.User = user
7575
database.Password = pass
7676
} else {
77-
fmt.Println(" -> remote: using postgres superadmin account (from POSTGRES_PASSWORD)")
77+
fmt.Println(" -> remote: using postgres superadmin account \"postgres\" (from env:POSTGRES_PASSWORD)")
7878
// only password available
7979
database.User = "postgres"
8080
database.Password = pass
@@ -84,9 +84,9 @@ func (database *DatabasePostgres) init() {
8484

8585
// get schema from env
8686
if database.Schema == "" {
87-
if val, ok := containerEnv["POSTGRES_DB"]; ok {
88-
fmt.Println(" -> remote: using postgres schema (from POSTGRES_DB)")
89-
database.Schema = val
87+
if schema, ok := containerEnv["POSTGRES_DB"]; ok {
88+
fmt.Println(fmt.Sprintf(" -> remote: using postgres schema \"%s\" (from env:POSTGRES_DB)", schema))
89+
database.Schema = schema
9090
}
9191
}
9292
}

0 commit comments

Comments
 (0)