2011-11-05 41 views
5

Phonegap v1.1.0, làm cách nào để truy cập đầu ra từ console.log (chuỗi)?Phonegap WP7 Visual Studio 2010 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 ! "); 

Nó cách đăng nhập vào cửa sổ xuất debug

+0

Thanx !! Điều này đã giúp tôi khắc phục một số vấn đề gây phiền nhiễu :) – VDP

Trả lời

1

console.log được định nghĩa như sau

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); 
      } 
     } 
    }; 
} 

Kết quả của cả hai debugConsole.log() và window.external.Notify () là cuộc gọi phương thức Debug.WriteLine (msg). Vì vậy, có khả năng bạn có thể chuyển hướng đầu ra gỡ lỗi tới ví dụ như tệp và lưu giữ thông tin này để có thể gỡ lỗi/xem lại thông tin này sau. Không cần kết nối với VS để gỡ lỗi sự cố, đôi khi nó có thể rất hữu ích, ví dụ mã

TextWriterTraceListener[] listeners = new TextWriterTraceListener[] 
{ 
    new TextWriterTraceListener("debug.log"), 
    new TextWriterTraceListener(Console.Out) 
}; 

Debug.Listeners.AddRange(listeners);