Feb 22, 2009

Microlog with Global Log Levels

This is the first day in ages that I have been able to work with Microlog. It is very nice to be back again and do some development.

There has been several users that have asked for a global log level in Microlog. My initial thought was that this is hard to do, if we should not implement a logging hierarchy. I would like to avoid logging hierarchies, since I think that this would make the Microlog core to complicated and big. Anyway I found a solution to add a global log level to the existing Microlog version, without implementing a logger hierarchy.

The solution is rather simple. You have a method called setGlobalLogLevel() in the Logger class. This is used for all Logger instances, except for those who override it. We have added the method getEffectiveLevel() to check the effective level for each Logger. This method is also found in Log4j, but in that case is has another semantic meaning. In Microlog we have a global level and an individual level, whereas in Log4j it is the hierarchy of Logger objects that decide the effective level.

The setup in the properties file looks like this:

The first line is used for setting the global log level. This is similar to how it was before. The new ability is used on the 2nd line, where the log level is set for a particular class.

I hope that this solution would suffice for most users. The next step is probably to introduce a hierachy of loggers. Since this will break the compability, this will be introduced in Microlog 2.0. But we have not still decided whether or not we will introduce a Logger hierarchy. What do you think?

1 comment:

Shopping Cart said...

Thanks for providind very useful information about to this liberary.Micrilog powerful logging library for mobile devices,It is smally but works very fast especially for mpbile devices.