Msw: Predicate for Logs

Created on 10 Oct 2020  路  3Comments  路  Source: mswjs/msw

First off thank you for the excellent library. It is amazingly helpful for mocking endpoints.

I have certain requests which are fired over and over again (for example an autosave endpoint, or polling the server for some information). I find logging very useful but I would like a way to filter out some of these more common requests. I saw the implementation of quiet in https://github.com/mswjs/msw/issues/111. Would it be possible to extend that concept to use a function which returns True for requests which should be logged and False for requests which should not be logged? The alternative I can think of is to override console.log which is probably less desirable.

feature

Most helpful comment

Can pick this up if @lukesmurray isn't. :)

All 3 comments

Hey, @lukesmurray. Thank you for the feedback!

I see no harm in us extending the quiet option to support a predicate function as a value.

worker.start({
  quiet(req, res) {
    // Conditionally suppress logs for certain requests.
    return req.url.href.includes('/foo')
  }
})

Would this suit your usage? If so, are you interested in making a pull request with these changes? I'll support you through the process to make sure we land an awesome extension.

Can pick this up if @lukesmurray isn't. :)

That is exactly what I imagined. Happy to let @balavishnuvj take this one.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kettanaito picture kettanaito  路  3Comments

luistak picture luistak  路  3Comments

tomalexhughes picture tomalexhughes  路  3Comments

abrudin picture abrudin  路  3Comments

balavishnuvj picture balavishnuvj  路  4Comments