Skip to content

Commit

Permalink
Make database log a sublogger of Bridge, like all other modules. (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
zopieux authored Jan 25, 2021
1 parent 500cb0c commit 95f6487
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Database struct {
Message *MessageQuery
}

func New(dbType string, uri string) (*Database, error) {
func New(dbType string, uri string, baseLog log.Logger) (*Database, error) {
conn, err := sql.Open(dbType, uri)
if err != nil {
return nil, err
Expand All @@ -50,7 +50,7 @@ func New(dbType string, uri string) (*Database, error) {

db := &Database{
DB: conn,
log: log.Sub("Database"),
log: baseLog.Sub("Database"),
dialect: dbType,
}
db.User = &UserQuery{
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (bridge *Bridge) GenerateRegistration() {
}

func (bridge *Bridge) MigrateDatabase() {
oldDB, err := database.New(flag.Arg(0), flag.Arg(1))
oldDB, err := database.New(flag.Arg(0), flag.Arg(1), bridge.Log)
if err != nil {
fmt.Println("Failed to open old database:", err)
os.Exit(30)
Expand All @@ -107,7 +107,7 @@ func (bridge *Bridge) MigrateDatabase() {
os.Exit(31)
}

newDB, err := database.New(bridge.Config.AppService.Database.Type, bridge.Config.AppService.Database.URI)
newDB, err := database.New(bridge.Config.AppService.Database.Type, bridge.Config.AppService.Database.URI, bridge.Log)
if err != nil {
fmt.Println("Failed to open new database:", err)
os.Exit(32)
Expand Down Expand Up @@ -223,7 +223,7 @@ func (bridge *Bridge) Init() {
bridge.AS.Log = log.Sub("Matrix")

bridge.Log.Debugln("Initializing database connection")
bridge.DB, err = database.New(bridge.Config.AppService.Database.Type, bridge.Config.AppService.Database.URI)
bridge.DB, err = database.New(bridge.Config.AppService.Database.Type, bridge.Config.AppService.Database.URI, bridge.Log)
if err != nil {
bridge.Log.Fatalln("Failed to initialize database connection:", err)
os.Exit(14)
Expand Down

0 comments on commit 95f6487

Please sign in to comment.