Skip to content

Commit

Permalink
Merge pull request #194 from pactflow/docs/document_suppressing_log_o…
Browse files Browse the repository at this point in the history
…utput

docs: document suppressing logging output
  • Loading branch information
YOU54F committed Mar 13, 2024
2 parents 6a5714c + f9b6cd6 commit a772f45
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,46 @@ The `path` argument contains a relative path to save the file into, already prep

The `data` field consists of a javascript object containing a pact file (check the [anatomy of a pact file](#anatomy-of-a-pact-file)).

## Log output

You can create your own instance of a `Logger`, the default is a [`console`](https://developer.mozilla.org/en-US/docs/Web/API/console)

If one wishes to suppress the output from pact-msw-adapter, you could use the following `emptyConsole` function.

```js
const emptyConsole = () => {
const emptyFunction = () => {};
const emptyConsole = {
log: emptyFunction,
debug: emptyFunction,
info: emptyFunction,
warn: emptyFunction,
error: emptyFunction,
group: emptyFunction,
groupCollapsed: emptyFunction,
groupEnd: emptyFunction,
};
return emptyConsole;
}
```

Pass the custom console to the `options.logger` key in `setupPactMswAdapter`

```js
import { PactFile, setupPactMswAdapter } from "./pactMswAdapter";

const server = setupServer();
const pactMswAdapter = setupPactMswAdapter({
server,
options: {
...options,
logger: emptyConsole()
},
});
```

_Note:_ - This will not control or affect msw's native logging.

## Pact files generation

`pact-msw-adapter` will dump all the recorded requests into pact files when `writeToFile` is called.
Expand Down

0 comments on commit a772f45

Please sign in to comment.