Write Cordova console.log to file

2019-05-07 13:25发布

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.

3条回答
Explosion°爆炸
2楼-- · 2019-05-07 13:59

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

查看更多
够拽才男人
3楼-- · 2019-05-07 14:00

You need to add plugin console plugin.

To add:

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

查看更多
Explosion°爆炸
4楼-- · 2019-05-07 14:04

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

查看更多
登录 后发表回答