-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Capture console.log instead of using separate log function #1
Comments
Hi @IjzerenHein, thanks for noticing this. We are using a logging abstraction layer in Javascript with this module, e.g. import FirebaseCrash from 'react-native-firebase-crash-report';
export default class Log {
constructor(props) {
this.logToConsole = props.logToConsole;
this.logToFirebase = props.logToFirebase;
}
log(msg) {
if (this.logToConsole) {
console.log(msg);
}
if (this.logToFirebase) {
FirebaseCrash.log(msg);
}
} However I think you are right, making it in native side is much better for performance. But it might not be a feature to this module IMO since it can be all done through editing |
Hi @ianlin. Yes you're true, you could integrate it in AppDelegate (that's exactly what I've done so far 🙃). Yet, I'd still love to see this in the form of an installable plugin rather than custom AppDelegate code. So, here is my case for using automatically hooking into
Also, I think it would be really nice if this is a feature of this plugin. Perhaps one that you could enable conditionally, but in my perception it should be enabled always when you choose to use this plugin. Also, most people don't know that you can intercept react-native's log messages. Having this code in a central plugin that everyone uses makes it much easier to maintain for all of us. Cheers :) |
That sounds great, will try to make it soon. Btw do you have any idea of overriding react-native's logging functions in Android? |
Hi! So for Android I currently only capture I'm using Javascript code to intercept console.log: function init() {
if (Platform.OS === 'android') {
console.log = interceptLog(console.log);
console.info = interceptLog(console.info);
console.error = interceptLog(console.error);
//console.debug = interceptLog(console.debug);
}
if (!__DEV__) {
global.ErrorUtils.setGlobalHandler(errorHandler);
}
}
function interceptLog(originalFn) {
return function() {
const args = Array.prototype.slice.apply(arguments);
let result = '';
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (!arg || (typeof arg === 'string') || (typeof arg === 'number')) {
result += arg;
}
else {
result += JSON.stringify(arg);
}
}
//originalFn.call(console, 'INTERCEPTED LOG: ' + result);
FirebaseCrash.log(result);
return originalFn.apply(console, arguments);
};
} |
@ianlin @IjzerenHein thanks for the code and the discussion, super helpful. Do any of you see any reason why the Cheers |
@temitope No, there's no reason why that code shouldn't work on iOS too. When I pasted the example, I happened to have a clause for Android only in there at that moment, no idea why anymore. I've been using it successfully for iOS as well. |
@IjzerenHein great news. thanks! |
Hi, I think it would be nicer if all
console.log
calls are automatically logged for crash reporting (instead of having to callFirebaseCrash.log
).Like this (Objective-C example):
It is described in more detail here:
https://medium.com/delivery-com-engineering/add-crashlytics-to-your-react-native-ios-app-69a983a9062a#.rg68fvfs7
The text was updated successfully, but these errors were encountered: