Skip to main content

lwuit logs nothing

10 replies [Last post]
mohsenof
Offline
Joined: 2011-09-26
Points: 0

I'm trying to log an exception using lwuit Log class.:

catch(Exception ex){         Log.setLevel(Log.DEBUG);              Log.e(ex);              Log.p("test error");              Log.showLog();  }

But it shows just an empty Form. Even the "test error" is not there.

I checked Log.getLogContent() and Log.getFileURL(). Both are null.

What's the problem?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

You need to use Log.getInstance().setFileWriteEnabled(true) in the beginning of your application for this feature to work. The log will be written to file removing the need to show the dialog in the first place. You can also set the location of said file manually.

mohsenof
Offline
Joined: 2011-09-26
Points: 0

Thank you for the response.

I added 2 below lines to the startting point of the project, right after Display.init(this)

Log.getInstance().setFileWriteEnabled(true);
Log.getInstance().setFileURL("file:///log.txt");

But it doesn't work yet.I checked for log.txt, it doesn't exist.

I notice is that Log.getInstance().getFileURL() is not null anymore. As you expect it is "file:///log.txt"

The strange thing is that when I call Log.getInstance().setFileWriteEnabled(true); then Log.getInstance().isFileWriteEnabled(); returns false but if I create an instance by calling constructor and then call these 2 methods, the result is true.

P.S. there's nothing about calling setFileWriteEnabled(true) in the javadoc or developer's guide. Shouldn't it be added there?

mohsenof
Offline
Joined: 2011-09-26
Points: 0

Don't any body have some experience with LWUIT log?

Any clues may help

vimald
Offline
Joined: 2010-11-06
Points: 0

As vPrise writely pointed out that the LWUIT logs writer need to be know the outstream hence by setting the write flag the logswriter is pointer to filesystem.

Log.getInstance().setFileWriteEnabled(true);<br />Log.getInstance().setFileURL(&quot;file:///log.txt&quot;);<br />

Now about your second line in the above code, you are trying to write a file 'log.txt' at the root '/' location which is not accessible in emulator nor on device.

  1. Incase of emulator, change your file path to "file:///root1/log.txt" and try it.
  2. Incase of device, its tricky, but a workable solution for Nokia devices is to fetch the photos directory location using System.property("fileconn.dir.photos") and putting the file at this location. So your file path may look like 'file:///C:/Images/log.txt'. Try it.
mohsenof
Offline
Joined: 2011-09-26
Points: 0

I did what you said and tested it on wtk emulator. But yet the problem exists. I chekced 'appdb' on my computer but there's no log files. Also the opened Form is empty.

I guess this is not the cause of my problem, because I have another project which creates a file and writes to it. And I use just the same path for files in that project. WTK automatically puts files in root1 folder and you don't need to set it as a part of the path .

Thank you anyway

vprise
Offline
Joined: 2003-11-07
Points: 0

That's odd. The URL seems wrong since it should include the root directory and not just the file immediately. You can ommit it and LWUIT would just write a file to the first root.

I just verified and writing to a log file works for me.

mohsenof
Offline
Joined: 2011-09-26
Points: 0

thank you for the effort vprise.

I put the logging code in a anothet thread and now it works. Both log-to-file and log-to-form is working now:

try{
            int i = 0;
            System.out.println(12 / i);
        }catch(final Exception ex){
            new Thread(new Runnable() {
                public  void run() {
                    Log log = Log.getInstance();
                    log.setFileWriteEnabled(true);
                    log.setFileURL(&quot;file:///root1/log.txt&quot;);
                    log.e(ex);
                    log.p(&quot;my small error&quot;);
                    log.showLog();
                }
            }).start();

There's some notes here:

1- as vimald said previously file url needs the folder name, otherwise sometimes you get such an exception:

IllegalArgumentException: Root is not specified (but it's just some times)

2- It's not possible to use LWUIT logging api on a lcdui Form. (or at least didn't work for me)

3- When working with FileConnection.create(), you don't need to specify the folder; it just puts the file in the root. I think it is better for LWUIT log to work like that because of consistency.

4- LWUIT log, just logs exception.toString(). Isn't it possible to log complete stack trace? I think it is really a needed feature

Thank you all.

vprise
Offline
Joined: 2003-11-07
Points: 0

I don't see why you will need a separate thread, never ran into this myself.

We always use absolute paths for maximum portability due to the flakiness of current working directory on devices. This is especially important in some platforms.

You can use the log in anything, you can't show a LWUIT UI with LCDUI.

There is no way whatsoever to extract a stack trace from an exception in CLDC/J2ME. So we have no way of logging that. We do log that on platforms that support stack trace print to stream.

mohsenof
Offline
Joined: 2011-09-26
Points: 0

"There is no way whatsoever to extract a stack trace from an exception in CLDC/J2ME."

Yeah, I've heard that too. Don't know how, but jarrut (http://jarrut.sourceforge.net) when used with microlog (http://microlog.microsuite.org/) can give you stack traces.

Unforunately it's not so easy to use.

vprise
Offline
Joined: 2003-11-07
Points: 0

Thanks for the Jarrut link, seems quite cool. You can ask these guys to support LWUIT logging as well...

We intend to build something similar to this in the future although we don't have concrete plans at this moment.