Phonegap v1.1.0,如何从console.log(字符串)访问输出?
// provide our own console if it does not exist, huge dev aid!
if(typeof window.console == "undefined")
{
window.console = {log:function(str){window.external.Notify(str);}};
}
// output any errors to console log, created above.
window.onerror=function(e){console.log("Error ::" + e);};
console.log("Installed console ! ");
它正在登录到调试输出窗口
答案 0 :(得分:1)
console.log定义如下
if(typeof window.console == "undefined")
{
window.console = {
log:function(str){
if(navigator.debugConsole){
navigator.debugConsole.log(str);
}
else
{// In case log messages are received before device ready
window.external.Notify("Info:" + str);
}
}
};
}
debugConsole.log()和window.external.Notify()的结果都是Debug.WriteLine(msg)方法调用。因此可能您可以将调试输出重定向到例如文件,并保留此信息以便稍后调试/查看此信息。调试问题不需要与VS的连接,有时它可能非常有用,代码示例
TextWriterTraceListener[] listeners = new TextWriterTraceListener[]
{
new TextWriterTraceListener("debug.log"),
new TextWriterTraceListener(Console.Out)
};
Debug.Listeners.AddRange(listeners);