Wifi IDE - Console log output

316 views
Skip to first unread message

wheelie tips

unread,
Dec 2, 2021, 10:45:27 AM12/2/21
to DroidScript
Hello all,

Is there anyway to set the Console log output to print full messages and not trimmed it once it passes a certain length? 

Cheers,
WT

Alan Hendry

unread,
Dec 2, 2021, 11:11:15 AM12/2/21
to DroidScript
HI,
I presume you are referring to debug.
You could try SetOnDebug to catch the debug in your own function
Regards, ah

wheelie tips

unread,
Dec 2, 2021, 11:22:44 AM12/2/21
to DroidScript

Thx Alan,

I do mean to the debug output; the above SetOnDebug does not solve the problem of the trimmed msg when using "console.log", for example when printing the text:
console.log( "An Android App Bundle is a publishing format that includes all your app's compiled code and resources, and defers APK generation and signing" );

in the debug output window it prints a trimmed msg:
"An Android App Bundle is a publishing format that includes all your app's compiled code and reso..."

Alan Hendry

unread,
Dec 2, 2021, 11:53:49 AM12/2/21
to DroidScript
HI,
Not really sure I understand.
I meant to use SetOnDebug to intercept the message (hoping it is complete)
then show the whole thing in a javascript alert or app.ShowPopup or textbox.SetText
(or perhaps break it up into two messages).
Could you post a bit of code?
Regards, ah

wheelie tips

unread,
Dec 3, 2021, 1:46:26 AM12/3/21
to DroidScript

Good morning Alan and thank you for your last reply.

Using an alert, popup, and such will block the code from running and/or be visible on the device when I need it on the computer; in any case, I bypassed it by breaking the printed message into 96 chars long (the length of the debug trimmed messages) and print them to the debug console; I then wrapped it in a Plugin for easier use;

For example, this is a comparison between using “console.log” and my cute little plugin:

app.LoadPlugin( “MultiLineLog” );
plg = app.CreateObject( “MultiLineLog” );

const longTxt = “A man is smoking a cigarette and blowing smoke rings into the air. His girlfriend becomes irritated with the smoke and says, “Can’t you see the warning on the cigarette pack? Smoking is hazardous to your health!”\nTo which the man replies, “I am a programmer. We don’t worry about warnings; we only worry about errors.””

console.log( longTxt );
console.log( “////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////“ );
plg.log( longTxt );

and the printed result shown in the screenshot below:
screenshot.png

here's the MultiLineLog Plugin for anyone who wants to use it.
Best,
WT


wheelie tips

unread,
Dec 3, 2021, 2:55:07 AM12/3/21
to DroidScript
an upgraded version of the Plugin, now supports color:
screenshot_2.png

download plugin from here.
Best,
WT

Steve Garman

unread,
Dec 4, 2021, 5:59:17 AM12/4/21
to DroidScript
Thanks for the multilinelog plugin WT
I only just got round to trying it and it's very useful

wheelie tips

unread,
Dec 4, 2021, 6:04:06 AM12/4/21
to DroidScript
Thank you Steve; happy to contribute.

Dave

unread,
Dec 5, 2021, 3:48:34 PM12/5/21
to DroidScript
That's nice... but if you have no limit on the size of the log lines, then you will hit problems when someone uses app.ReadFile() on a very large file.

Maybe you should some sort of limit of say 1024 bytes (if not done already)

wheelie tips

unread,
Dec 5, 2021, 3:50:58 PM12/5/21
to DroidScript
good point, I have a few more little tweaks i want to add to it, probably get to in the coming days

Dave

unread,
Dec 5, 2021, 3:51:01 PM12/5/21
to DroidScript
Or is it just the console.log() function that you have overridden ?

wheelie tips

unread,
Dec 5, 2021, 3:57:45 PM12/5/21
to DroidScript
correct, I split the string and print it line by line using "console.log()"

wheelie tips

unread,
Dec 5, 2021, 4:00:51 PM12/5/21
to DroidScript
function MultiLineLog()
{
    this.log = function( msg, color ) 
    { 
        var msgLength;
        var numChunks;
        var chunks;
        var msgColor;

        if (color == null)
        {
            msgLength = 96;
            numChunks = Math.ceil(msg.length / msgLength);
            chunks    = new Array(numChunks);

            for (let i = 0, o = 0; i < numChunks; ++i, o += msgLength) 
            {
                console.log(msg.substr(o, msgLength));
            }
        }
        else
        {
            msgLength = 68;
            numChunks = Math.ceil(msg.length / msgLength);
            chunks    = new Array(numChunks);
            msgColor  = "<div style='color:" + color + "'>";

            for (let i = 0, o = 0; i < numChunks; ++i, o += msgLength) 
            {
                console.log(msgColor + msg.substr(o, msgLength) + "</div>");
            }
        }   
    }    
}

wheelie tips

unread,
Dec 6, 2021, 2:22:41 PM12/6/21
to DroidScript
an updated version to the Plugin; current version adds above any print the name of the called function.

MultiLineLog.png
Download plugin here.
Best,
WT

Right2TheV0id

unread,
Jun 29, 2022, 10:32:12 PM6/29/22
to DroidScript
I tried this plugin and has always "Outside any function" as the calling function name.
A little research pointed out that arguments.callee does not work in strict mode (which was my problem).
After some modifications I managed to make it work in strict mode.
I share it here if it can help/inspire someone: 

```js
function MultiLineLog()
{
    var lastCaller;

    this.log = function( msg, color )
    {
        try
        {
            var caller = null;
            try
            {
                // Throws a dummy error to access stack trace.
                throw new Error( "dummy" );
            }
            catch( e )
            {
                try
                {
                    //alert( e.stack ); // for debug purposes.
                   
                    caller = e.stack.match( /\s{4}at\s(.*)\s\(/g )[1]
                                    .match( /\s{4}at\s(.*)\s\(/  )[1]
                                    .replace( "HTMLScriptElement.", "" );
                   
                    // Special case for eval functions (like debug view commands).
                    if( caller.indexOf( "(eval" ) !== -1 )
                    {
                        caller = "eval";
                    }
                   
                    //alert( caller ); // for debug purposes.
                }
                catch( e )
                {
                    // Falls back to the obsolete arguments.callee method.
                    caller = arguments.callee.caller.name.toString();
                }
            }
        }
        catch
        {
            caller = null;
        }
       
        if( caller !== lastCaller )
        {
           lastCaller = caller;
           
           if( caller )
           {
               // Escape anonymous callers ("<anonymous>" in stack).
               var escapedCaller = lastCaller.replace( "<", "&lt;" ).replace( ">", "&gt;" );
               
               console.log( "<div style='color:yellow'> === " + escapedCaller + " ===" );
           }
           else
           {
               console.log( "<div style='color:red'> === Outside any function ===" );
           }
        }
       
        var msgLength = 68;
        var numChunks = Math.ceil( msg.length / msgLength );
        var msgColor  = color ? "<div style='color:" + color + "'>" : "";
       
        for( var i = 0, o = 0; i < numChunks; ++i, o += msgLength )
        {
            console.log( msgColor + msg.substr( o, msgLength ) );
        }  
    }
}
```

I doubt that it can be a reliable solution (as Error.stack is not standard), and it might have (a little) impact on performances.
But maybe it can help to debug your apps.

Harris

unread,
Oct 31, 2023, 2:24:58 AM10/31/23
to DroidScript
Hi all, I am very new to DroidScript.
I tried to use this plugin in a Node app but the app.CreateObject() always returns null.
It works fine in Native app.
Could anyones show me how to use it in Node app?
Thanks!

Reply all
Reply to author
Forward
0 new messages