better logging
This commit is contained in:
@@ -23,6 +23,9 @@ type Repository struct {
|
||||
}
|
||||
|
||||
func New(logger mlogger.Logger, conn *db.MongoConnection) (*Repository, error) {
|
||||
if logger == nil {
|
||||
logger = zap.NewNop()
|
||||
}
|
||||
if conn == nil {
|
||||
return nil, merrors.InvalidArgument("mongo connection is nil")
|
||||
}
|
||||
@@ -30,10 +33,19 @@ func New(logger mlogger.Logger, conn *db.MongoConnection) (*Repository, error) {
|
||||
if client == nil {
|
||||
return nil, merrors.Internal("mongo client is not initialised")
|
||||
}
|
||||
db := conn.Database()
|
||||
if db == nil {
|
||||
return nil, merrors.Internal("mongo database is not initialised")
|
||||
}
|
||||
dbName := db.Name()
|
||||
logger = logger.Named("storage").Named("mongo")
|
||||
if dbName != "" {
|
||||
logger = logger.With(zap.String("database", dbName))
|
||||
}
|
||||
result := &Repository{
|
||||
logger: logger.Named("storage").Named("mongo"),
|
||||
logger: logger,
|
||||
conn: conn,
|
||||
db: conn.Database(),
|
||||
db: db,
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
@@ -43,12 +55,12 @@ func New(logger mlogger.Logger, conn *db.MongoConnection) (*Repository, error) {
|
||||
}
|
||||
paymentsStore, err := store.NewPayments(result.logger, result.db)
|
||||
if err != nil {
|
||||
result.logger.Error("Failed to initialise payments store", zap.Error(err))
|
||||
result.logger.Error("Failed to initialise payments store", zap.Error(err), zap.String("store", "payments"))
|
||||
return nil, err
|
||||
}
|
||||
tgStore, err := store.NewTelegramConfirmations(result.logger, result.db)
|
||||
if err != nil {
|
||||
result.logger.Error("Failed to initialise telegram confirmations store", zap.Error(err))
|
||||
result.logger.Error("Failed to initialise telegram confirmations store", zap.Error(err), zap.String("store", "telegram_confirmations"))
|
||||
return nil, err
|
||||
}
|
||||
result.payments = paymentsStore
|
||||
|
||||
Reference in New Issue
Block a user