IBM Worklight 6.0 - 如何将日志写入文件并将其发回? [英] IBM Worklight 6.0 - How to write logs to a file and send them back?

查看:181
本文介绍了IBM Worklight 6.0 - 如何将日志写入文件并将其发回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用worklight 6.0,我可以使用 WL.Logger.debug(msg);

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.xml 中的日志记录级别,以便能够查看不同的日志记录数据。在那里你还决定哪个文件将包含这些日志(默认情况下为messages.log) - 请参阅基于应用程序服务器的位置文档。

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.



客户端记录(应用程序)

如果您想存储日志行,稍后将它们发送回某个后端系统,您可以使用回调函数将日志结束到服务器上的文件

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

示例代码:

在此代码中 logHandler()函数只处理我决定要处理的包,方法是创建一个新的 Logger 对象(appLogic )对于我要登录应用程序的特定日志。

Example code:
In this code the logHandler() function treats only packages that I have decided I want to process, by create a new Logger object ("appLogic") for specific logs I want to log in the app.

您需要在自己的应用程序中执行什么操作,例如,而不是显示 alert()使用Cordova File API 将这些日志行保存在文件中,然后在需要时通过Worklight Adapters或AJAX调用或电子邮件应用程序等将它们发送回后端......

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:


var appLogic = new WL.Logger.create({pkg: 'appLogic'});

function wlCommonInit(){
  appLogic.debug("log from app");
}


common \ js \\ \\ _initOptions.js:


 var wlInitOptions = {
    connectOnStartup : false,
    analytics : {
      enabled: false
      //url : ''
  },
  logger : {enabled: true, level: 'debug', stringify: true, pretty: false,
      tag: {level: false, pkg: true}, whitelist: [], blacklist: [], callback: logHandler},    
 };

 function logHandler(message, priority, pkg) {
   if (pkg == 'appLogic') {
      alert (message);
   }
}

if (window.addEventListener) {
  window.addEventListener('load', function() { WL.Client.init(wlInitOptions); }, false);
} else if (window.attachEvent) {
  window.attachEvent('onload',  function() { WL.Client.init(wlInitOptions); });
}



这篇关于IBM Worklight 6.0 - 如何将日志写入文件并将其发回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆