Skip to main content

Logging in Java ME

9 replies [Last post]
davjoh
Offline
Joined: 2007-07-18

Is there any decent logging mechanism for Java ME? I know there's a couple of open-source projects that do it, so was wondering does anybody have any experience with those?

I was also wondering how to create my own logger, and was thinking about writing a log to the RMS. But would that be very inefficient for frequent logging of messages?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
terrencebarr
Offline
Joined: 2004-03-04

Hi,

JSR 47 is the logging API but unfortunately it never got much traction in Java ME land.

You're right that there are a few open source packages available but I have not yet tried them.

Do you need to log during development? If yes, then with many devices System.out goes to the console on the PC or into a file on the device and you can use that.

If you are looking for logging functionality once your app is deployed to users then your choices for persistent storage is RMS or PIM files. In both cases you'll need to implement caching and LRU policies to minimize the activity on the persistent store as some devices are very slow in accessing flash storage.

-- Terrence

davjoh
Offline
Joined: 2007-07-18

Awesome, thanks Terrence.

Yes, logging to console is easy enough, and that's how I do stuff at the moment.

But I was thinking of some way of logging once it's deployed to a phone, and as you point out, it's not neccessarily too straight forward.

Another consideration of course is making sure to be able to get the logs back to a PC or server somewhere!

I think I'll stick with trusty old System.out for now...

jaywayjohan
Offline
Joined: 2008-06-18

I would recommend that you try out MicroLog: http://sourceforge.net/projects/microlog

It is compatible with Log4j, but is built from ground up to make it possible to run in a Java ME. If you are familiar with Log4j, it should be easy to get going.

You could log to System.out, a RecordStore or a file (which could be transferred to a PC via USB). It also has support for some easy formatting.

BTW a new version is now out. Please try it out. Feedback is very welcome!

terrencebarr
Offline
Joined: 2004-03-04

jaywayjohan,

Thanks for the post. I've created a page on our wiki about logging:

http://wiki.java.net/bin/view/Mobileandembedded/LoggingResource

-- Terrence

pandora808
Offline
Joined: 2004-07-06

You know, I actually just recently started a project on java.net to do some more advanced logging in Java ME. More of a Logger/Debugger actually. So far the console logger, network logger and bluetooth logger are finished.

I know some sony ericssons allow you to do bluetooth debugging, but not in linux, and only with those ericsson devices, just too limited for me. So, off I went to do something for the community, and hope that other people could use the same solution to the common on-device debugging issues that I've come across in the past years.

check it out, maybe add it to the LoggingResource wiki if you think it's appropriate?
https://logmeadvanced.dev.java.net/

Message was edited by: pandora808

terrencebarr
Offline
Joined: 2004-03-04

pandora808,

Great. Also posted to the wiki. PS: Of course, the wiki can be edited by any java.net member so feel free to update it yourself as necessary.

-- Terrence

jaywayjohan
Offline
Joined: 2008-06-18

We have worked very hard to improve Microlog. One of the most important additions is the PatternFormatter, which works like the PatternLayout found in Log4j. We have also added a lot of new appenders:

On-device appenders
===================
-ConsoleAppender - Appends to the console, e.g. System.out.'
-RecordStoreAppender - Appends to the RecordStore.
-FileAppender - Appends to a file using a FileConnection.
-CanvasAppender - Appends to a Canvas.
-FormAppender - Appends to a Form.

Off-device appenders
====================
-BluetoothSerialAppender - Appends to a Bluetooth serial connection (btspp).
-SerialAppender - Appends to a serial port (CommConnection).
-SmsAppender - Appends to a cyclic buffer and send the buffer as an SMS.
-MmsAppender (for MMS and/or e-mail) - Appends to a cyclic buffer and send the buffer as an SMS.
-DatagramAppender - Appends to a datagram and send it using UDP.
-SyslogAppender - Appends to syslog server.
-SocketAppender - Appends to a socket connection (also SSL).
-S3FileAppender - Appends to a file, as in the FileAppender, and stores the file on Amazon S3.
-S3BufferAppender - Appends to a cyclic buffer and stores it as a file on Amazon S3.

We have also made a Bluetooth server that is executable on both Java ME and Java SE. The setup is dead easy:

1. Pair the Bluetooth devices, e.g. your mobile phone and your laptop.
2. Start the server on your laptop.
3. Start your MIDlet with Microlog included.

That it is! Now you could watch your log on your laptop :)

jaywayjohan
Offline
Joined: 2008-06-18

Correction: The MMSAppender sends and/or MMS or e-mail.

jaywayjohan
Offline
Joined: 2008-06-18

Hi,

I have released a new version of Microlog that contains the above mentioned features. I am also proud to announce that a quickstart guide is included.

Please download it from:
http://sourceforge.net/projects/microlog/

Please post comments and/or feedback on the Microlog forums.

Happy logging!

Best Regards
Johan