mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
da138106f2
Our logger middleware can be quite noisy in production, logging all RPC requests. It has been updated to have more condensed logs in production builds, but preserving the existing logging for development builds.
36 lines
919 B
JavaScript
36 lines
919 B
JavaScript
import log from 'loglevel';
|
|
|
|
/**
|
|
* Returns a middleware that logs RPC activity. Logging is detailed in
|
|
* development builds, but more limited in production builds.
|
|
*
|
|
* @param {{ origin: string }} opts - The middleware options
|
|
* @returns {Function}
|
|
*/
|
|
export default function createLoggerMiddleware(opts) {
|
|
return function loggerMiddleware(
|
|
/** @type {any} */ req,
|
|
/** @type {any} */ res,
|
|
/** @type {Function} */ next,
|
|
) {
|
|
next((/** @type {Function} */ cb) => {
|
|
if (res.error) {
|
|
log.debug('Error in RPC response:\n', res);
|
|
}
|
|
if (req.isMetamaskInternal) {
|
|
return;
|
|
}
|
|
if (process.env.METAMASK_DEBUG) {
|
|
log.info(`RPC (${opts.origin}):`, req, '->', res);
|
|
} else {
|
|
log.info(
|
|
`RPC (${opts.origin}): ${req.method} -> ${
|
|
res.error ? 'error' : 'success'
|
|
}`,
|
|
);
|
|
}
|
|
cb();
|
|
});
|
|
};
|
|
}
|