Added structured logging across services and repositories. Updated SQL queries to use parameterized placeholders for better readability and security. Enhanced error handling for external service communication.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const DefaultLogValueLimit = 4096
|
||||
|
||||
func ToLogJSON(value any) string {
|
||||
if value == nil {
|
||||
return "null"
|
||||
}
|
||||
|
||||
data, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return TruncateForLog(fmt.Sprintf("%+v", value), DefaultLogValueLimit)
|
||||
}
|
||||
|
||||
return TruncateForLog(string(data), DefaultLogValueLimit)
|
||||
}
|
||||
|
||||
func TruncateForLog(value string, limit int) string {
|
||||
if limit <= 0 || len(value) <= limit {
|
||||
return value
|
||||
}
|
||||
|
||||
return value[:limit] + "...(truncated)"
|
||||
}
|
||||
Reference in New Issue
Block a user