Hi all,
My Avalon journey has led me to ask about configuration of loggers in
Merlin and possibly LogKit in general. Basically I'm going to want to create
custom configured loggers for different instances of a component.
To throw the above statement into Avalon/Merlin-speak .. it sounds like what you want to is define a custom log target or possibly a custom formatter.
I have moderate experience with log4j but none with LogKit though they look reassuringly similar.
e.g. One instance of a component will require ContextMap for host
specific information to go in the log, it will have an INFO level LogTarget
and another LogTarget with a filter to only allow ERROR and higher messages.
Log4J takes an Object as the log argument whereas the Avalon Framework Logger interface takes a String as a log argument. To present additional information in the log message would you need associate your ContextMap as a thread-local variable and grab this value within the log target or formatter when generating the log message.
Eventually I will need to reconfigure some of these while the system is running.
This is what I want to archive as well - but it's not there yet. The content that is in place still needs work to be able to expose manageable log target factories and log target instances (as distinct from factories that are pure configuration driven).
So far these seem easily achieveable just by reading the logkit javadocs, my
problem is how to proceed in the avalon framework w.r.t components.
My initial scratchings have me making my own component-container that creates and configures Loggers to supply to the components it also creates.
Or is it prefereable, to have merlin create the loggers and the components
fetch them from the ServiceManager, (I will almost certainly do this in the
early stages if possible to ease my transition instead of writing a container).
If your component implements the LogEnabled interface Merlin will supply a logger instance to your component automatically. The instance that is supplied is associated with the component partition - so for example, if your component is located at the address /root/gizmo/widget, the logging category assigned to the component will be root.gizmo.widget. The component can also declare subsidiary channels that it uses - e.g. a sub-channel named data would be assigned as root.gizmo.widget.data. You can declare a components sub-channel assumption within the meta-info associated with the component.
Under your component directive (block.xml or whatever) you can qualify the logging priority and target that the logging channel is assigned to. For example:
<component name="widget"> <categories priority="info" target="widget-context-target"> <category name="data" priority="error"/> </categories> </component>
In the above case your saying that the logging channel root.gizmo.widget should be created with a priority INFO and assigned to the log target with an id of widget-context-target.
Under the kernel configuration you can setup the definition of the logging system. here is an example from the current 3.3 logging config.
<kernel> <logging> <factories> <factory type="file" class="org.apache.avalon.logging.logkit.factory.FileTargetFactory"/> </factories> <targets> <file id="widget-context-target"> <filename>widget.log</filename> <append>true</append> <rotation type="revolving" init="1" max="10"> <size>100k</size> </rotation> </file> </targets> </logging> </kernel>
Please keep in mind that this is not final. In fact there are the following changes that I am currently considering. In the above example the <file> element is named "file" because this is the 'type' assigned when declaring the factory. I want to change this to something like:
<targets> <target type="file" id="widget-context-target"> : </target> </targets>
Secondly, the approach to specifying custom log target factories is still be working though - but basically it should look something like:
<factories> <factory type="file" artifact="my-group/my-logging-factory?version=1.2"> <!-- your parameters here --> </factory> </factories>
Lastly - there are a few items still to take care of - for example the ability to define custom formatters (but this should be completed reasonably soon).
Is there a good reference of how to configure logkit using xml (initially).
Not really. The Excalibur Logging package documentation (on which the above is based) is scattered across mail archives and javadocs. However complete specification docs will arrive as part of Merlin 3.3 delivery cycle. If you included - usage example and tutorials from users are very highly appreciated!
Does anyone have good advice on using multiple loggers with merlin or a better suggestion on how to implement this?
I would suggest starting with the 3.3 capabilities and see what is possible (which implies building from CVS or working with SNAPSHOT builds). Feedback on the implementation would definitely be appreciated.
Cheers, Steve.
thanks in advance, Jon
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--
|------------------------------------------------| | Magic by Merlin | | Production by Avalon | | | | http://avalon.apache.org/merlin | | http://dpml.net/merlin/distributions/latest | |------------------------------------------------|
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]