This commit is contained in:
19
internal/utils/logging.go
Normal file
19
internal/utils/logging.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func LogMessageFromDatabaseOperation(entityName string, operation string, dbOp func() error) (string, error) {
|
||||
err := dbOp()
|
||||
logMsg := fmt.Sprintf("%s %sd successfully", cases.Title(language.English).String(entityName), operation)
|
||||
|
||||
if err != nil {
|
||||
logMsg = fmt.Sprintf("%s %s encountered an error", cases.Title(language.English).String(operation), entityName)
|
||||
}
|
||||
|
||||
return logMsg, err
|
||||
}
|
||||
Reference in New Issue
Block a user