Mar 10, 2009

How to do Logging

I tend to get into a lot of discussions about logging. It could have something to do with my Microlog development. Sometimes I find it hard to argue what is good practices when it comes to logging. So I searched the Internet and found these good articles on the subject:
I hope that you read them thoroughly, because the are definitely worth reading. But until then you are maybe interesting on my comments about them?

Starting with the first article, I must say that all of the tips are really good. From my point of view, the last rule "7. Do not log with System.out or System.err" is especially important. The first sentence says it all "Always use a log framework, it can handle logging better than you." Of course I want you to use a logging framework. If you are working with Java ME or Android development, please try out Microlog!

The second article is a little more general. The first advice is a little bit tricky; "No debugging logs in production". Microlog has no built-in feature to solve this, so I usually recommend to use the pre-processor found in MTJ. If you are running in other environments, like vi, you could use the ProGuard pre-processor. The second advice "Look through your logs" is easy to do with Microlog, if you log to a server. Microlog has the capability to log to several types of servers. The easiest would be to log to a syslog daemon or to Amazon S3. Most syslog daemons have some sort of filtering feature and export functions. This should make it easy for you to filter out the interesting stuff. The 3rd rule; "Never log locally" is as you now understand fairly easy with Microlog.

I hope that these articles will give you some good advice that you will be able to use.

9 comments:

Fiora said...

Hi,

nice blog!!

I'm whith some doubts about microlog can do or not.

I have to log the output of a third program, but I dont have access to its code. So, there is no way I can input some code direct to the program.

I want to know if microlog can log the output of a third program whithout access to its source. Something like redirecting its output.

Thanks.

My Open Source Software Development Blog said...

Hi,

first of all I thank you very much for your kinf words. It is always nice to know what people think about my work.

Second I think that Microlog is not what you are seeking for. The ConsoleAppender found in the Java ME version of Microlog, uses System.out for logging. But the System.out is not possible to re-direct on Java ME platforms. Compared to Java SE, this is a clear disadvantage. But it could be possible to re-direct on the Android platform.

On some mobile platforms, such as Symbian,it is possible to re-direct your output from an application you do not have access to the source code. I have written about this in the FAQ section for Microlog:
http://microlog.sourceforge.net/snapshot/microlog-logger/faq.html

If you give me some more details on your platform, I could answer your question with a little bit easier and more concrete.

Regards
Johan

Fiora said...

Wow,

thanks for the quick answer Johan.

I work as a tester and I'm trying to develop an automated test tool for mobile app. The main purpose is to test J2ME app, but we want test native app too(for Symbian, Windows Mobile and Android).

The biggest problem I'm having now is to do the asserts, because I dont know how to access the output of a program. So I woul like how to log its output whitout modifying its source code.

About the redirect of System.out and System.err, see this article(it really works):
http://wiki.forum.nokia.com/index.php/How_to_get_System.out_output_from_a_MIDlet_and_save_it_to_a_file_in_S60_devices

Thanks,
Fiora

My Open Source Software Development Blog said...

Hi,

it is maybe something like Motorolas Gatling test framework you are looking for? It actually uses Microlog for logging on the devices :)

Read more about it here:
https://opensource.motorola.com/sf/projects/gatling

Regards
Johan

My Open Source Software Development Blog said...

BTW I have not used the Gatling framework, but the test organisation at my current work uses it with great success.

Regards
Johan

Fiora said...

Ummm..... I already read gatling and I had the impression that it test APIs.... but no problem, I'll ready it again. =)

Well, what do you test at your work? APIs or (GUI, Usability, Performance, Compatibility,...) testing?

Thanks,
Fiora

My Open Source Software Development Blog said...

Hmmm... I guess you are right, the Gatling project is not suitable for GUI testing. My mistake...

They use it for API and performance testing at my work.

Sorry, but I am out of ideas :(

Regards
Johan

Fiora said...

Dont worry, and thanks for all the explanation and help.

And continue with microlog! It's a usefull toll!!

Fiora.

My Open Source Software Development Blog said...

Thank you very much!

I hope that you find what you are looking for.

Regards
Johan