Does anyone knows if it is possible the console.log
to write to a file or something similar?
I have already log for my application but it is only written on the console. For purposes of remote debugging
I need the existing log to be written to a file too.
I thought of creating a File and write my log inside that file but that will make me duplicate the existing log code. So it could be better if it is possible to redirect where the console.log writes.
My application uses Ionic
, Cordova
and is hybrid for iOS
and android using crosswalk browser plugin.
This is the plugin cordova-plugin-logtofile that suits your requirement. But unfortunately it works only in Android.
Since you are using ionic framework, have a look at this too - FileLogger
You need to add plugin console plugin.
To add:
cordova plugin add https://github.com/apache/cordova-plugin-console
Yes, you can create a logging service to wrap the console.log and the cordova file plugin: http://ngcordova.com/docs/plugins/file/ (content from 2019 via waybackmachine).
When you start the app, open a file for writing, then simply use the service to log to the console and the file.
So instead of console.log you use LoggingService.log().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With