logfile

57 views
Skip to first unread message

howud...@gmail.com

unread,
Oct 4, 2016, 9:37:21 PM10/4/16
to CodenameOne Discussions
is there a wiki or instructions somewhere that describe how to read/write from the iOS log?  I'm getting occasional null pointer errors

Shai Almog

unread,
Oct 4, 2016, 11:04:02 PM10/4/16
to CodenameOne Discussions, howud...@gmail.com
Not much beyong the javadocs as far as I recall. Our official way for reading is the sendLog() method which we use a lot but it's a pro feature.
Writing is just Log.p(),Log.e() where you can just write whatever you want into the log. I don't have experience in reading the log other than sendLog since that works for us.

Dave Dyer

unread,
Oct 8, 2016, 12:02:26 AM10/8/16
to CodenameOne Discussions, howud...@gmail.com
assuming you have a web site to receive it, some simple perl can suck in whatever is posted to it
and store it to a permanent log.   I use this for debugging and catching the unexpected from deployed
applications.
 
The biggest trick is getting a stack trace (which is also a "pro" feature for no good reason IMO).

I can share my code to (1) get stacktraces (2) post them to a web site (3) receive and log them.
The particular code I use may not be suitable for everyone, but the general methods ought to
be part of any deployed application.

Peter Carlson

unread,
Oct 9, 2016, 5:10:39 PM10/9/16
to Dave Dyer, CodenameOne Discussions
I am interested in getting the stacktrace. In my desktop java apps I
redirect System.out and Sytem.err uploading to a website I already
have, but others might be intersted in that.

Peter

Shai Almog

unread,
Oct 9, 2016, 11:05:22 PM10/9/16
to CodenameOne Discussions, ddyer-...@real-me.net, howud...@gmail.com
Log.e() prints the stack trace etc. Grabbing system out/err is a bit of a technical challenge across platforms.

Dave Dyer

unread,
Oct 10, 2016, 6:17:52 PM10/10/16
to CodenameOne Discussions, ddyer-...@real-me.net, howud...@gmail.com

I use this code to capture the contents of a log file.  Its a bit obscure because it threads
a needle through the standard codename1 class "Log" to create a temporary log file.

class LogCapture extends Log
{    Log oldLog;
    StringWriter myWriter;
    LogCapture()
    { oldLog = Log.getInstance();
      install(this); 
    }
    protected Writer createWriter() throws IOException
    {    return(myWriter = new StringWriter());
    }
   
    public String dispose()
    {
        install(oldLog);
        return(myWriter.toString());
    }
}

then, this code can capture a stack trace as a string

    public static String getStackTrace(Throwable t)
    {
        LogCapture cap = new LogCapture();
        Log.e(t);
        return cap.dispose();   
    }

Rather than redirect System.out, I use my own redirectable printer for debugging
messages. Depending on the situation, I redirect it to a network stream, a string
builder, or a logging window that's part of my app.


howud...@gmail.com

unread,
Dec 2, 2016, 4:10:13 PM12/2/16
to CodenameOne Discussions, howud...@gmail.com
ok, so I have a situation that requires some flexibility.  The tablets are air gapped so using the "cloud based crash reporting" wont work.  We can use email based reporting (they can save the logfile as a draft and then send when they are connected)

However the sendlog function is static (not instance based) so I cant override it.  Can the following, or similar, change be made?  Or is there another way to send the log?

    public static void sendLog() {
    if (instance != null) instance._sendLog();
    }
    
    protected void _sendLog() {
       .... current sendLog continues here .....


Shai Almog

unread,
Dec 3, 2016, 1:23:37 AM12/3/16
to CodenameOne Discussions, howud...@gmail.com
You can file an RFE for that although I'm not sure when we'll get around to it. 3.6 is already overbooked and 3.7 is filling up quickly with tasks.

Dave Dyer

unread,
Dec 4, 2016, 8:05:22 PM12/4/16
to CodenameOne Discussions, howud...@gmail.com

See this post, which includes a snippet that extracts stack traces using a temporary logfile.
You can adapt this to capture all the log events - but except for stack traces I think you're
better off using a private mechanism to log info.

https://groups.google.com/forum/#!searchin/codenameone-discussions/logfile%7Csort:relevance/codenameone-discussions/kCbXGCqmt2o/N6vvLXtECQAJ

howud...@gmail.com

unread,
Dec 4, 2016, 10:58:36 PM12/4/16
to CodenameOne Discussions, howud...@gmail.com

The problem though, unless I'm missing something, is in a thread, with an unhandled crash the code checks isCrashBound, (CodenameOneThread#handleException) which would be false and so would never call the newly installed logger (Log.e())
    public static void handleException(Throwable err) {
        if(Log.isCrashBound()) {
            Log.e(err);
            Log.sendLog();
        }
    }
Reply all
Reply to author
Forward
0 new messages