Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap WP7 Visual Studio 2010 console.log

Phonegap v1.1.0, how do I access output from console.log(string)?

// 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 ! ");

It's logging to the debug output window

like image 590
jdc Avatar asked Nov 13 '22 15:11

jdc


1 Answers

console.log is defined as follows

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

Results of both debugConsole.log() and window.external.Notify() is Debug.WriteLine(msg) method call. So potentially you can redirect debug output to for example file and persist this information to be able debug/review this information later. No connection to VS is required to debug the problem, sometimes it could be very helpful, code example

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

Debug.Listeners.AddRange(listeners);
like image 62
Sergei Grebnov Avatar answered Dec 24 '22 11:12

Sergei Grebnov