I am using worklight 6.0 and I am able to log data to a console using WL.Logger.debug("msg");
.
My question is: How to write all of these logs to a file?
My requirement is to store these logs on the mobile device itself so that if some problem occurs, the user will be able to report the problem by attaching that log file. In the app there will be a menu "Report problem", if the user clicks on that, email is opened with this log attached automatically.
Server-side logging (adapters):
Related question: Worklight 5.0.6.1 - System.out.println() logging from Worklight adapter is not working
Basically, you need to change the logging level in the application server's
server.xml
in order to be able to view different logging data. There you also decide which file will house these logs (by default messages.log) - see documentation for location based on your application server.Client-side logging (application):
Related question: How to use WL.Logger api to output log messages to a file
If you would like to store your log lines and later on send them back to some backend system, you can use a Callback function to send the logs to a file on your server
Example code:
In this code the
logHandler()
function treats only packages that I have decided I want to process, by create a newLogger
object ("appLogic") for specific logs I want to log in the app.What you would need to do in your own app, for example, instead of displaying an
alert()
is to use the Cordova File API to save these log lines in a file and then, when required, to send them back to your backend via Worklight Adapters or AJAX calls or an email app, etc...common\js\main.js:
common\js\initOptions.js: