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 console.log and the cordova file plugin: http://ngcordova.com/docs/plugins/file/
When you start the app, open a file for writing, then simply using the service to log to console and the file.
so instead of console.log you use LoggingService.log()