React native by default pushed logs to adb with all the network request & application logs, which when grip with - adb logcat *:S ReactNativeJS:V
gives us all logs from react native.
Ask is in production mode the urls are exposed in logs & can we disbale all logs which are generated by ReactNativeJS
.
Tried to disbale remote logging in react native & marked debuggable false in android but still there are logs with ReactNativeJS
Any clue will be appreciated.
Please note:- Question is not about removing console.log , its about react native JS bridge logs when we run adb logcat in production apk there are logs taged with ReactNativeJS - The Ask is related to those logs to be removed.
React native by default pushed logs to adb with all the network request & application logs, which when grip with - adb logcat *:S ReactNativeJS:V
gives us all logs from react native.
Ask is in production mode the urls are exposed in logs & can we disbale all logs which are generated by ReactNativeJS
.
Tried to disbale remote logging in react native & marked debuggable false in android but still there are logs with ReactNativeJS
Any clue will be appreciated.
Please note:- Question is not about removing console.log , its about react native JS bridge logs when we run adb logcat in production apk there are logs taged with ReactNativeJS - The Ask is related to those logs to be removed.
Share Improve this question edited Apr 4 at 12:13 KOTIOS asked Mar 24 at 20:07 KOTIOSKOTIOS 11.1k3 gold badges41 silver badges67 bronze badges3 Answers
Reset to default 3 +75have you tried to Override Console Methods in JavaScript ?
Manually disable console. methods in production:*
if (!__DEV__) {
console.log = () => {};
console.info = () => {};
console.warn = () => {};
console.error = () => {};
console.debug = () => {};
}
This is the most effective and cross-platform-safe way to disable logs in production mode.
You can also try to Strip Console Logs via Babel Plugin.
You can use babel-plugin-transform-remove-console in your Babel config for production builds:
Install the package and then configure babel.config.js:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
env: {
production: {
plugins: ['transform-remove-console'],
},
},
};
This strips all console.* calls at build time in production mode.
Btw, you can Use both:
- JS override of console logs (for safety)
- Babel plugin to remove console logs (to reduce bundle size and completely strip logs)
This guarantees no logs from ReactNativeJS in production builds.
Hope that helps.
I would suggest that you should completely go with babel-plugin-transform-remove-console
Console logs are completely removed at build time, eliminating any execution overhead and improving performance. Since console.log and other debug statements are stripped out, the production build is more optimized with a smaller bundle size. Unlike overriding console.log with an empty function, which still incurs a runtime cost, this method removes the calls entirly, ensuring no performance impact. Additionaly, it applies globally to all files without requiring any manual code modifications, making the process efficient.
Steps to Implement it...
- Install the Babel plugin:
npm install babel-plugin-transform-remove-console --save-dev
- Add this to your
babel.config.js
:module.exports = { presets: ['module:metro-react-native-babel-preset'], env: { production: { plugins: ['transform-remove-console'], }, }, };
That's it! Now, all console.log
calls will be completely removed in production builds.
The most reliable solution is to remove console statements at build time:
npm install babel-plugin-transform-remove-console --save-dev
Then add to your .babelrc or babel.config.js:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
env: {
production: {
plugins: ['transform-remove-console']
}
}
};
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744230135a4564206.html
评论列表(0条)