Make database log a sublogger of Bridge, like all other modules. (#260)
This commit is contained in:
parent
500cb0cd7c
commit
95f6487912
@ -38,7 +38,7 @@ type Database struct {
|
|||||||
Message *MessageQuery
|
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)
|
conn, err := sql.Open(dbType, uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -50,7 +50,7 @@ func New(dbType string, uri string) (*Database, error) {
|
|||||||
|
|
||||||
db := &Database{
|
db := &Database{
|
||||||
DB: conn,
|
DB: conn,
|
||||||
log: log.Sub("Database"),
|
log: baseLog.Sub("Database"),
|
||||||
dialect: dbType,
|
dialect: dbType,
|
||||||
}
|
}
|
||||||
db.User = &UserQuery{
|
db.User = &UserQuery{
|
||||||
|
6
main.go
6
main.go
@ -96,7 +96,7 @@ func (bridge *Bridge) GenerateRegistration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) MigrateDatabase() {
|
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 {
|
if err != nil {
|
||||||
fmt.Println("Failed to open old database:", err)
|
fmt.Println("Failed to open old database:", err)
|
||||||
os.Exit(30)
|
os.Exit(30)
|
||||||
@ -107,7 +107,7 @@ func (bridge *Bridge) MigrateDatabase() {
|
|||||||
os.Exit(31)
|
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 {
|
if err != nil {
|
||||||
fmt.Println("Failed to open new database:", err)
|
fmt.Println("Failed to open new database:", err)
|
||||||
os.Exit(32)
|
os.Exit(32)
|
||||||
@ -223,7 +223,7 @@ func (bridge *Bridge) Init() {
|
|||||||
bridge.AS.Log = log.Sub("Matrix")
|
bridge.AS.Log = log.Sub("Matrix")
|
||||||
|
|
||||||
bridge.Log.Debugln("Initializing database connection")
|
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 {
|
if err != nil {
|
||||||
bridge.Log.Fatalln("Failed to initialize database connection:", err)
|
bridge.Log.Fatalln("Failed to initialize database connection:", err)
|
||||||
os.Exit(14)
|
os.Exit(14)
|
||||||
|
Loading…
Reference in New Issue
Block a user