【问题标题】:Is there any way to display WL.Logger error messages in Visual Studio 2012?有没有办法在 Visual Studio 2012 中显示 WL.Logger 错误消息?
【发布时间】:2014-08-14 23:53:10
【问题描述】:

我正在为 Windows Phone 8 开发 Worklight 应用程序。通过 Visual Studio 2012 构建到设备时,我可以在 Visual Studio 控制台中看到通过 WL.Logger 的调试方法记录的消息。但是,我看不到使用 WL.Logger 的错误方法记录的任何消息。

我没有在 Visual Studio 中看到任何其他控制台,a WL.Logger documentation 没有提供太多帮助 - 对 Visual Studio 的唯一引用是“调试消息显示在 Microsoft Visual Studio 2012 控制台中”。 - 明显没有提到错误消息。

有没有办法在 Visual Studio 2012 中显示 WL.Logger 错误消息?

【问题讨论】:

    标签: visual-studio visual-studio-2012 logging windows-phone-8 ibm-mobilefirst


    【解决方案1】:

    我从未使用过 Visual Studio,因此请谨慎对待。也许您可以覆盖对 Windows 环境的调用以使用您想要的任何记录器。比如我们用console.log

    if (running on windows env) {
       WL.Logger.error = function () {
         console.log.apply(console, arguments); //or alert(...)
      }
    }
    

    您可以使用WL.Client.getEnvironment() API 获取当前环境。

    如果我不得不猜测,WL.Logger.error 用于错误消息的console.error(假设它已定义)由于某种原因没有被打印到控制台。

    【讨论】:

    • 根据您的建议,我做了一些研究,发现在初始化记录器时,您可以添加一个回调,该回调将在每次调用消息时发生。我的解决方案是定义一个回调,当环境是 Windows Phone 8 并且日志优先级为错误时,将使用 console.log() 打印出消息。我的回调是:function(message, priority, pkg) { if (WL.Client.getEnvironment() === WL.Environment.WINDOWS_PHONE_8 && priority === 'error') { console.log(message); } }(抱歉。我不知道如何格式化 cmets。)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 2014-03-09
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多