Skip to content

Commit

Permalink
Reduce logging in production builds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Gudahtt committed Sep 4, 2023
1 parent 52f4936 commit e046338
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions app/scripts/lib/createLoggerMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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
* @returns {Function}
Expand All @@ -14,12 +15,20 @@ export default function createLoggerMiddleware(opts) {
) {
next((/** @type {Function} */ cb) => {
if (res.error) {
log.error('Error in RPC response:\n', res);
log.debug('Error in RPC response:\n', res);
}
if (req.isMetamaskInternal) {
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();
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export function createMethodMiddleware(hooks) {
selectHooks(hooks, hookNames),
);
} catch (error) {
console.error(error);
if (process.env.METAMASK_DEBUG) {
console.error(error);
}
return end(error);
}
}
Expand Down Expand Up @@ -101,7 +103,9 @@ export function createSnapMethodMiddleware(isSnap, hooks) {
selectHooks(hooks, hookNames),
);
} catch (error) {
console.error(error);
if (process.env.METAMASK_DEBUG) {
console.error(error);
}
return end(error);
}
}
Expand Down

0 comments on commit e046338

Please sign in to comment.