@new10com/axios-logger
Advanced tools
Comparing version 0.2.9 to 0.2.10
@@ -5,2 +5,3 @@ "use strict"; | ||
const constants_1 = require("../constants/constants"); | ||
const buffer_1 = require("buffer"); | ||
class Formatter { | ||
@@ -42,5 +43,5 @@ constructor(config) { | ||
if (maxLogContentLength !== undefined) { | ||
const bodyLengthInKv = new TextEncoder().encode(bodyAsString).length; | ||
if (bodyLengthInKv > maxLogContentLength) { | ||
return `Body is too long to be displayed. Length: ${bodyLengthInKv}kb. Max length: ${maxLogContentLength}kb.`; | ||
const bodyLengthInBytes = buffer_1.Buffer.byteLength(bodyAsString); | ||
if (bodyLengthInBytes > maxLogContentLength) { | ||
return `Body is too long to be displayed. Length: ${bodyLengthInBytes} bytes. Max length: ${maxLogContentLength} bytes.`; | ||
} | ||
@@ -47,0 +48,0 @@ } |
@@ -35,3 +35,3 @@ "use strict"; | ||
const body = 'Hello how are you?'.repeat(100); | ||
expect(formatter.prettyFormatBody({ body, maxLogContentLength: 10 })).toEqual(`Body is too long to be displayed. Length: 1802kb. Max length: 10kb.`); | ||
expect(formatter.prettyFormatBody({ body, maxLogContentLength: 10 })).toEqual(`Body is too long to be displayed. Length: 1802 bytes. Max length: 10 bytes.`); | ||
}); | ||
@@ -38,0 +38,0 @@ }); |
{ | ||
"name": "@new10com/axios-logger", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"description": "Library that should be used as axios request/response interceptor for logging in a pretty format request/response details", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
167226
2339