Skip to content

Commit 54e33a2

Browse files
committed
initial commit
1 parent a1550f2 commit 54e33a2

File tree

8 files changed

+82
-65
lines changed

8 files changed

+82
-65
lines changed

cns/logger/cnslogger.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,28 @@ func (c *logger) Request(tag string, request any, err error) {
148148
c.sendTraceInternal(msg, lvl)
149149
}
150150

151-
func (c *logger) Response(tag string, response any, returnCode types.ResponseCode, err error) {
152-
c.logger.Response(tag, response, int(returnCode), returnCode.String(), err)
151+
func (c *logger) Response(tag string, response any, returnCode types.ResponseCode, properties any, err error) {
152+
c.logger.Response(tag, response, int(returnCode), returnCode.String(), properties, err)
153153
if c.th == nil || c.disableTraceLogging {
154154
return
155155
}
156156
var msg string
157157
lvl := ai.InfoLevel
158+
159+
// Create a string for properties if they exist
160+
props := ""
161+
if properties != nil {
162+
props = fmt.Sprintf(" Properties: %+v", properties)
163+
}
164+
158165
switch {
159166
case err == nil && returnCode == 0:
160-
msg = fmt.Sprintf("[%s] Sent %T %+v.", tag, response, response)
167+
msg = fmt.Sprintf("[%s] Sent %T %+v.%s", tag, response, response, props)
161168
case err != nil:
162-
msg = fmt.Sprintf("[%s] Code:%s, %+v %s.", tag, returnCode.String(), response, err.Error())
169+
msg = fmt.Sprintf("[%s] Code:%s, %+v %s.%s", tag, returnCode.String(), response, err.Error(), props)
163170
lvl = ai.ErrorLevel
164171
default:
165-
msg = fmt.Sprintf("[%s] Code:%s, %+v.", tag, returnCode.String(), response)
172+
msg = fmt.Sprintf("[%s] Code:%s, %+v.%s", tag, returnCode.String(), response, props)
166173
}
167174
c.sendTraceInternal(msg, lvl)
168175
}

cns/logger/log.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type loggershim interface {
1818
LogEvent(aitelemetry.Event)
1919
Errorf(string, ...any)
2020
Request(string, any, error)
21-
Response(string, any, types.ResponseCode, error)
21+
Response(string, any, types.ResponseCode, any, error)
2222
ResponseEx(string, any, any, types.ResponseCode, error)
2323
SendMetric(aitelemetry.Metric)
2424
}
@@ -85,8 +85,8 @@ func Request(tag string, request any, err error) {
8585
}
8686

8787
// Deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead.
88-
func Response(tag string, response any, returnCode types.ResponseCode, err error) {
89-
Log.Response(tag, response, returnCode, err)
88+
func Response(tag string, response any, returnCode types.ResponseCode, properties any, err error) {
89+
Log.Response(tag, response, returnCode, properties, err)
9090
}
9191

9292
// Deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead.

cns/logger/v2/shim.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func (s *shim) Request(msg string, data any, err error) {
3939
s.z.Sugar().Infow("Request", "message", msg, "data", data, "error", err)
4040
}
4141

42-
func (s *shim) Response(msg string, data any, code types.ResponseCode, err error) {
43-
s.z.Sugar().Infow("Response", "message", msg, "data", data, "code", code, "error", err)
42+
func (s *shim) Response(msg string, data any, code types.ResponseCode, properties any, err error) {
43+
s.z.Sugar().Infow("Response", "message", msg, "data", data, "code", code, "properties", properties, "error", err)
4444
}
4545

4646
func (s *shim) ResponseEx(msg string, request, response any, code types.ResponseCode, err error) {

0 commit comments

Comments
 (0)