Comments (7)
Hi! So for Android I currently only capture console.log
, console.info
and console.error'
Any log-messages that are logged in the native-code are currently nog logged.
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);
};
}
from react-native-firebase-crash-report.
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 console.log
:
- Console.log support n+1 arguments so you can do things like this
console.log("hello", "world: ", {a: 1, b: 2})
- Standard way to support log-levels using
console.info
,console.warn
,console.error
- Warnings throws by react-native are automatically logged (they use
console.warn
) - Code portability, when you use
console.log
, the code can be used on the web as well, and could easily switch to another crash reporting tool if you want - Log messages generated by other plugins are also captured
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 :)
from react-native-firebase-crash-report.
That sounds great, will try to make it soon. Btw do you have any idea of overriding react-native's logging functions in Android?
from react-native-firebase-crash-report.
@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.
from react-native-firebase-crash-report.
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 AppDelegate.m
without React Native's bridge. Let me know if it make sense to you or not, cheers!
from react-native-firebase-crash-report.
@ianlin @IjzerenHein thanks for the code and the discussion, super helpful.
Do any of you see any reason why the interceptLog
code @IjzerenHein shared shouldn't (or couldn't) be used for iOS? I noticed that it was only done for android in the code. If possible I would love to avoid modifying the AppDelegate.m
file entirely and simply do this in pure JS on the react-native side for both platforms.
Cheers
from react-native-firebase-crash-report.
@IjzerenHein great news. thanks!
from react-native-firebase-crash-report.
Related Issues (15)
- Assertion failed: (NO), function -[RNFirebaseCrashReport report:] HOT 3
- Android config lacks manual instructions HOT 1
- update README to reflect this change HOT 1
- Bitcode bundle could not be generated in Release HOT 1
- report() on iOS crash HOT 1
- Getting Multiple dex files define Error
- how can i see logs?
- How do i get it to send a report for Firebase Console?
- Log unhandled exceptions
- ld: library not found for -lGoogleToolboxForMac
- Feature: Support for source-maps to decode release stack traces HOT 3
- Why Android installation instructions are different that Firebase Default? HOT 1
- React native is now at RN30 - is this correct: compile 'com.facebook.react:react-native:0.20.+'?: HOT 1
- Android installation fails. HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-firebase-crash-report.