mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Reduce logging in production builds (#20694)
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.
This commit is contained in:
parent
10ccbfc68d
commit
da138106f2
@ -1,7 +1,8 @@
|
|||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a middleware that logs RPC activity
|
* 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
|
* @param {{ origin: string }} opts - The middleware options
|
||||||
* @returns {Function}
|
* @returns {Function}
|
||||||
@ -14,12 +15,20 @@ export default function createLoggerMiddleware(opts) {
|
|||||||
) {
|
) {
|
||||||
next((/** @type {Function} */ cb) => {
|
next((/** @type {Function} */ cb) => {
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
log.error('Error in RPC response:\n', res);
|
log.debug('Error in RPC response:\n', res);
|
||||||
}
|
}
|
||||||
if (req.isMetamaskInternal) {
|
if (req.isMetamaskInternal) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info(`RPC (${opts.origin}):`, req, '->', res);
|
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();
|
cb();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -65,7 +65,9 @@ export function createMethodMiddleware(hooks) {
|
|||||||
selectHooks(hooks, hookNames),
|
selectHooks(hooks, hookNames),
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
if (process.env.METAMASK_DEBUG) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
return end(error);
|
return end(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +103,9 @@ export function createSnapMethodMiddleware(isSnap, hooks) {
|
|||||||
selectHooks(hooks, hookNames),
|
selectHooks(hooks, hookNames),
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
if (process.env.METAMASK_DEBUG) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
return end(error);
|
return end(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user