Nov 1, 2008

Upgrading Voxtr with Microlog

What a sin! I am involved in the Voxtr open source project. The initial code was not made by me, so I found those awful System.out.println() statements. But fear no more; The Voxtr has been upgraded with Microlog.

I would like to take the opportunity to describe how simple it is to use Microlog. First of all you must download Microlog. Next up is to unzip the file that you downloaded. The included microlog.jar must be copied to your project and added to your buildpath. How this is done, depends on your development enviroment.

The second step is to setup Microlog. I prefer to use a properties file. The biggest advantage is that you do not need to change any code when you want to change your Microlog settings. Use the supplied file that is called Copy this to the source root of your project or to your resource folder if you have one. To configure Microlog using the properties file you add the following code to your main class, which in most cases is the MIDlet class. The setup code looks like this:
Properties properties = new Properties();
Microlog is now configured according to the settings in your file. In each class that you like to do some logging, you add the following code:
private final static Logger log = Logger.getLogger();

public void someMethod(){
// Do the actual logging
log.debug("MicroLog is working!");
That is it! Insert logging statements where you would normally put System.out.println() statements.

What good is all the logging if you do not know how to view the log? In this example, the logging is done in two destinations. The ConsoleAppender outputs to the same place all your System.out.println() would go. If you run your MIDlet in the emulator, the output is shown in some kind of console. In Eclipse, this is the "Console" view. The second output destination is the recordstore. To view it you use the RecordStoreLogViewer. Add the RecordStoreLogViewer MIDlet to the JAD file. When you have executed your main MIDlet, it is just a matter of switching to the RecordStoreLogViewer MIDlet. Select the "Load" item in the menu and the log is loaded on the screen. The image below shows the RecordStoreLogViewer with Voxtr log data.

What I have shown here is the setup that I recommend that you start with. The ConsoleAppender is good when using the emulator, and the RecordStoreAppender is good when executing on the target device. This is the default settings in the supplied file. When it is time to do field test, or similar, it is recommended that you start using one of the off-device appenders, for example the MMSAppender. The MMSAppender could be used to send MMS and/or e-mails to the addresses of your choice. Other choices are the Amazon S3 appenders which I have blogged about earlier. I will not go into more details about the off-device appenders right now, I will save it for later. Stay tuned!


lulei said...

It's a very useful tool.

Today, I start use it, but I have a problem that it can't output delimiter.
HelloMicroLogMIDlet [DEBUG] MicroLog is working.

The default delimiter ":" don't output.

Soon , I set delimiter use this code

but it can't work!

My Open Source Software Development Blog said...

I have tested it and it works for me. To figure out what the problem is I need to know the following:

1. In what file did you put the settings.

2. How do you set which formatter to use?

Please check that you have the following setup code:

Properties properties = new Properties(this);

I hope this will help you.

lulei said...

Thanks for your help!

I had a mistake at write properties file. I'm a novice at use Log4j.

It works now!

I still have some questions.

1.Can it prints the line number where we use the logger at.

2.What's function of the %r in configure the PatterFormatter.

lulei said...

Or give me a tips where can I find thess questions answer.

Best Regards

My Open Source Software Development Blog said...


1. You could use the Microlog instrument tool. This changes the code before transferring it to the phone.

2. Use %r , since PatternFormatter is somewhat compatible with the PatternLayout.

For more information I could recommend the FAQ found at or the Microlog forums.

lulei said...

Thank you very much!

Shopping Cart said...


Thanks for the sharing this such a nice and useful tools information.I really don,t know about to the Microlog and its different tools,But now i have know very well and will use it as soon as.