adds structs for all logging features

This commit is contained in:
Hyatt 2025-03-07 06:33:22 -06:00
parent dd6b899df3
commit 83afc2b0f2
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA
2 changed files with 51 additions and 17 deletions

View File

@ -6,6 +6,7 @@ import (
"log/slog"
"os"
"regexp"
"strings"
)
func New(c Customization) {
@ -88,7 +89,7 @@ func SetNumericLevel(level int) {
func setDefaults(c *Customization) error {
// \/ \/ \/ REQUIRED FIELDS \/ \/ \/ //
// format, can be one of "json" or "text"
switch {
case len(c.Format) == 0:
@ -124,14 +125,12 @@ func setDefaults(c *Customization) error {
return errors.New("Invalid application id, must be a valid uuid string.")
}
// /\ /\ /\ REQUIRED FIELDS /\ /\ /\ //
return nil
}
func Fatal(msg string, attrs ...interface{}) {
func Fatal(operation, correlationID, msg string, attrs ...interface{}) {
L.Log.Log(
L.Ctx,
LevelFatal,
@ -140,7 +139,7 @@ func Fatal(msg string, attrs ...interface{}) {
)
}
func Error(msg string, attrs ...interface{}) {
func Error(operation, correlationID, msg string, attrs ...interface{}) {
L.Log.Log(
L.Ctx,
slog.LevelError,
@ -149,7 +148,7 @@ func Error(msg string, attrs ...interface{}) {
)
}
func Warn(msg string, attrs ...interface{}) {
func Warn(operation, correlationID, msg string, attrs ...interface{}) {
L.Log.Log(
L.Ctx,
slog.LevelWarn,
@ -158,7 +157,7 @@ func Warn(msg string, attrs ...interface{}) {
)
}
func Info(msg string, attrs ...interface{}) {
func Info(operation, correlationID, msg string, attrs ...interface{}) {
L.Log.Log(
L.Ctx,
slog.LevelInfo,
@ -167,7 +166,7 @@ func Info(msg string, attrs ...interface{}) {
)
}
func Debug(msg string, attrs ...interface{}) {
func Debug(operation, correlationID, msg string, attrs ...interface{}) {
L.Log.Log(
L.Ctx,
slog.LevelDebug,
@ -176,7 +175,7 @@ func Debug(msg string, attrs ...interface{}) {
)
}
func Trace(msg string, attrs ...interface{}) {
func Trace(operation, correlationID, msg string, attrs ...interface{}) {
L.Log.Log(
L.Ctx,
LevelTrace,

View File

@ -3,6 +3,7 @@ package log
import (
"context"
"log/slog"
"time"
)
// primary struct
@ -14,13 +15,47 @@ type Log struct {
// field customization
type Customization struct {
Application CustomizationValue
Format string
TimeStamp struct {
Key string
Format string
}
Type CustomizationValue
Application string
Format string
TimeStamp TimeStamp
Type string
MobileApplication MobileApplication
Context RequiredContext
Extra ValueAdd
}
type CustomizationValue string
type TimeStamp struct {
Key string
Format string
}
type MobileApplication struct {
DeviceModel string
DeviceBrand string
OsType string
OsVersion string
}
type RequiredContext struct {
AuditID string
Channel string
Customer string
DestPort string
HttpMethod string
JvmThread string
RemoteIP string
RequestID string
RequestParams string
ResponseCode int
ResponseTime time.Duration
SessionID string
SubOperation string
Uri string
UserID string
}
type ValueAdd struct {
Customer string
Product string
RequestDomicile string
}