views:

37

answers:

4

I have an application with many different parts, it runs on OSGi, so there's the bundle lifecycles, there's a number of message processors and plugin components that all can die, can be started and stopped, have their setup changed etc.

I want a way to get a good picture of the current system status, what components are up, which have problems, how long they have been running for etc. I think that logging, especially in combination with custom appenders (I'm using log4j), is a good part of the solution and does help ad-hoc analysis as well as live monitoring.

Normally, I would classify lifecycle events as INFO level, but what I really want is to have them separate from what else is going on in INFO. I could create my own level, LIFECYCLE.

The lifecycle events happen in various different areas and on various levels in the application hierarchy, also they happen in the same areas as other events that I want to separate them from. I could introduce some common lifecycle management and use that to distinguish the events from others. For instance, all components that have a lifecycle could implement a particular interface and I log by its name.

Are there good examples of how this is done elsewhere? What are considerations?

+1  A: 

Have you though about using separate loggers for these events ?

This is the typical way of handling this kind of issue, I think.

Riduidel
A: 

This doesn't sound like a log level to me. It is more of a seperate logger hirachy.

The typical logger hierarchy everybody uses is based on the package names. But I recommend to use separate hierarchies, using prefixes. If you prefix class and package name with LIFECYCLE, you can turn these messages on, off or route them to a special place with the standard configuration options of log4j or slf4j or pretty much every reasonable logging framework.

Jens Schauder
A: 

log4 uses the concept of ThreadContext.Stacks["NDC"] (formerly just NDC http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html). At each lifecycle event, you push the current context onto the stack, and at the conclusion of that event you pop it off the stack again. Done with care, it can give you a pretty handy trace of where you are in the call sequence with each log entry.

codepoke
A: 

Logging is not the best solution for this. The fact you are talking about custom log levels is a definite design 'smell'.

If you want current status then you need monitoring and on Java this means JMX. Now the fact you're also doing OSGi makes this a bit more complex, though people have been working on this: http://code.google.com/p/maexo/

hbunny
Logging is not *the* solution but, as I wrote, I think it is a good *part of* the solution. I have two different scenarios for this information, one being some kind of frontend that shows me, and lets me manipulate, the components' status, and the other one being ad-hoc troubleshooting and general system health analysis. The former is a lot about my own application logic, and very little about frameworks. For the latter, logging is great because everything else in the system logs, too, and there's great tools, e. g. Splunk.
Hanno Fietz