如何在运行时获取所有控制台消息以登录Cordova iOS? [英] How do I get all console messages to log on Cordova iOS at runtime?

查看:61
本文介绍了如何在运行时获取所有控制台消息以登录Cordova iOS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在iOS的Cordova下运行WKWebview应用程序时,我使用 console.debug console.info登录Web应用程序的消息没有输出到Xcode控制台或我的日志中。但是, console.log 消息 正在得到输出。我如何才能输出所有日志消息?

When I am running my WKWebview application under Cordova on iOS, messages that I log in my web application using console.debug and console.info are not getting output to the Xcode console or in my logs. console.log messages are getting output however. How can I get all of my log messages to output?

推荐答案

在对进行了大量研究和审查之后cordova.js 源代码,我意识到我的 console.info 消息未记录的原因是因为Cordova在以下环境下运行时会覆盖控制台对象iOS。默认情况下,仅 console.log 消息, console.error console.warn 消息输出。这样做的原因是Cordova记录器支持以下日志级别:

After much research and reviewing of the cordova.js source, I realized that the reason why my console.info messages were not getting logged is because Cordova overrides the console object when running under iOS. By default, only console.log messages, console.error, and console.warn messages are output. The reason for this is that the Cordova logger supports the following log levels:


  • LOG

  • 错误

  • 警告<-默认级别

  • INFO

  • DEBUG

  • LOG
  • ERROR
  • WARN <-- DEFAULT LEVEL
  • INFO
  • DEBUG

,并且WARN是默认日志级别。这意味着仅输出在WARN级别和更高级别记录的消息,因此 console.warn console.error console.log 消息将仅输出。要更改日志级别,您将需要执行以下操作:

and WARN is the default log level. This means that only messages logged at WARN level and above will be output, so console.warn, console.error and console.log messages will only be output. To change the log level, you will need to do the following:

1)类似于使用Cordova的方式 exec 函数通过加载其模块,您还需要在JavaScript中加载Cordova记录器模块。要加载记录器模块,请将其添加到您的javascript中:

1) In a similar fashion to how you would use the Cordova exec function by loading its module, you will also need to load the Cordova logger module in your javascript. To load the logger module, add this to your javascript:

var logger = require('cordova / plugin / ios / logger');

2)接下来,您需要做的所有工作,以便将默认日志记录级别从WARN更改为另一个级别,例如DEBUG,是在初始化代码中的适当位置添加以下调用。插入此代码的位置将取决于您的应用程序,但是在上面的步骤1中声明的上述 logger 模块将需要在范围内。

2) Next, all you need to do in order to change the default logging level from WARN to another level, such as DEBUG, is to add the following call at the appropriate place in your initialization code. Where you insert this code, will depend on your application, but the above logger module that you declared in step 1 above will need to be in scope.

logger.level('DEBUG');

可以使用的级别如上所述:'LOG','ERROR','WARN','INFO','DEBUG'

Levels you can use are as mentioned above: 'LOG', 'ERROR', 'WARN', 'INFO', 'DEBUG'

或者,您还应该能够使用Cordova日志记录模块定义的级别常量: logger.LOG,logger.ERROR,logger.WARN,logger.INFO,logger.DEBUG 。我没有尝试过,但是应该可以。

Alternatively you should also be able to use the level constants that the Cordova logging module defines: logger.LOG, logger.ERROR, logger.WARN, logger.INFO, logger.DEBUG. I haven't tried this, but it should work.

希望这会在以后节省一些时间,因为我找不到任何文档。

Hopefully this helps save others some time in the future since I was unable to find any documentation on this.

这篇关于如何在运行时获取所有控制台消息以登录Cordova iOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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