@@ -200,10 +200,10 @@ func (logger *Logger) rotate() error {
200200 return nil
201201}
202202
203- // toJSONString converts any object to a JSON string for logging purposes.
203+ // ToJSONString converts any object to a JSON string for logging purposes.
204204// When the object contains json.RawMessage fields, they will be properly formatted
205205// instead of being shown as byte arrays. Falls back to %+v if JSON marshaling fails.
206- func toJSONString (obj interface {}) string {
206+ func ToJSONString (obj interface {}) string {
207207 if obj == nil {
208208 return "null"
209209 }
@@ -219,31 +219,31 @@ func toJSONString(obj interface{}) string {
219219// Request logs a structured request.
220220func (logger * Logger ) Request (tag string , request interface {}, err error ) {
221221 if err == nil {
222- logger .Printf ("[%s] Received %T %s." , tag , request , toJSONString (request ))
222+ logger .Printf ("[%s] Received %T %s." , tag , request , ToJSONString (request ))
223223 } else {
224- logger .Errorf ("[%s] Failed to decode %T %s %s." , tag , request , toJSONString (request ), err .Error ())
224+ logger .Errorf ("[%s] Failed to decode %T %s %s." , tag , request , ToJSONString (request ), err .Error ())
225225 }
226226}
227227
228228// Response logs a structured response.
229229func (logger * Logger ) Response (tag string , response interface {}, returnCode int , returnStr string , err error ) {
230230 if err == nil && returnCode == 0 {
231- logger .Printf ("[%s] Sent %T %s." , tag , response , toJSONString (response ))
231+ logger .Printf ("[%s] Sent %T %s." , tag , response , ToJSONString (response ))
232232 } else if err != nil {
233- logger .Errorf ("[%s] Code:%s, %s %s." , tag , returnStr , toJSONString (response ), err .Error ())
233+ logger .Errorf ("[%s] Code:%s, %s %s." , tag , returnStr , ToJSONString (response ), err .Error ())
234234 } else {
235- logger .Errorf ("[%s] Code:%s, %s." , tag , returnStr , toJSONString (response ))
235+ logger .Errorf ("[%s] Code:%s, %s." , tag , returnStr , ToJSONString (response ))
236236 }
237237}
238238
239239// ResponseEx logs a structured response and the request associate with it.
240240func (logger * Logger ) ResponseEx (tag string , request interface {}, response interface {}, returnCode int , returnStr string , err error ) {
241241 if err == nil && returnCode == 0 {
242- logger .Printf ("[%s] Sent %T %s %T %s." , tag , request , toJSONString (request ), response , toJSONString (response ))
242+ logger .Printf ("[%s] Sent %T %s %T %s." , tag , request , ToJSONString (request ), response , ToJSONString (response ))
243243 } else if err != nil {
244- logger .Errorf ("[%s] Code:%s, %s, %s %s." , tag , returnStr , toJSONString (request ), toJSONString (response ), err .Error ())
244+ logger .Errorf ("[%s] Code:%s, %s, %s %s." , tag , returnStr , ToJSONString (request ), ToJSONString (response ), err .Error ())
245245 } else {
246- logger .Errorf ("[%s] Code:%s, %s, %s." , tag , returnStr , toJSONString (request ), toJSONString (response ))
246+ logger .Errorf ("[%s] Code:%s, %s, %s." , tag , returnStr , ToJSONString (request ), ToJSONString (response ))
247247 }
248248}
249249
0 commit comments