Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write Cordova console.log to file

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.

like image 871
panos Avatar asked Apr 11 '16 10:04

panos


3 Answers

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

like image 69
Gandhi Avatar answered Oct 22 '22 14:10

Gandhi


You need to add plugin console plugin.

To add:

cordova plugin add https://github.com/apache/cordova-plugin-console

like image 41
Dhruv Avatar answered Oct 22 '22 15:10

Dhruv


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().

like image 32
Samuel Goldenbaum Avatar answered Oct 22 '22 16:10

Samuel Goldenbaum