Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer in logs #69

Open
mo4islona opened this issue Sep 18, 2020 · 4 comments
Open

Buffer in logs #69

mo4islona opened this issue Sep 18, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@mo4islona
Copy link

mo4islona commented Sep 18, 2020

It is always frustrating when request/response contains a buffer. Dumping in console as is totally useless because of huge amount of data inside and causes a harder debug of other requests.

#55 will help in a certain way. Though it will be nice to have an option to completely exclude buffer data from logging.

Now

[Axios][Response] GET http://example.com/some_file_.pdf {"type":"Buffer","data [255,216,255,224,0,16,74,70,73,70,0,1,1,0,
0,72,0,72,0,0,255,219,0,67,0,1,1,1,1,1,1,2,1,1,2,3,2,2,2,3,4,3,3,3,3,4,6,4,4,4,4,4,6,7,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,9,9,9,9,9,
11,11,11,11,11,11,11,11,11,11,255,219,0,67,1,2,2,2,3,3,3,5,3,3,5,11,8,6,8,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,255,194,0,17,8,3,32,4,176,3,1,34,0,2,17,1,3,17,1,255,196,0,
29,0,1,0,1,4,3,1,0,0,0,0,0,0,0,0,0,0,0,2,1,6,7,8,3,5,9,4,255,196,0,27,1,1,0,2,3,1,1,0,0,0,0,0,0,0,0,0,0,0,4,6,2,3,5,7,1,255,218,0,12,3,1,
0,2,16,3,16,0,0,1,188,120,143,90,240,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,225,157,182,215,178,225,91,207,171,
151,231,232,128,103,172,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,188,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
...and so on....
...many lines...

Want to

[Axios][Response] GET http://example.com/some_file_.pdf [Buffer]
@hg-pyun
Copy link
Owner

hg-pyun commented Nov 2, 2020

I need for option! I will consider.

@hg-pyun hg-pyun added the enhancement New feature or request label Dec 23, 2020
@UncleGrim
Copy link

UncleGrim commented May 29, 2021

One solution to solving this problem is to leverage the mixin loggers.

Sample code below for how I achieved a similar result:

       axiosInstance.interceptors.request.use((request) => {
            request.headers['Authorization'] = '<REDACTED>';
            request.headers.buffer = request.headers.buffer ? '<REDACTED>' : undefined;
            return AxiosLogger.requestLogger(request);
        }, AxiosLogger.errorLogger);

This will update the headers generated on a request object and replace with the string <REDACTED>. Similar concept can be taken for response payloads.

// Sample Request logged
[Axios][Request] GET https://example.com/some_file_.pdf {"buffer":"<REDACTED>","Content-Type":"application/json; charset=UTF-8","Connection":"Keep-Alive","Accept":"application/json","Authorization":"<REDACTED>"}

@cernadasjuan
Copy link

cernadasjuan commented Aug 19, 2021

Hi!

I had the same issue, the next piece of code resolves it:

axiosInstance.interceptors.response.use(
  (response) =>
     responseLogger(response, {
       data: response.config.responseType !== 'arraybuffer', // Don't log response body for binary responses
     }),
  errorLogger
)

@hg-pyun
Copy link
Owner

hg-pyun commented Aug 21, 2021

@cernadasjuan Thank you for report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants