Veerappan Saravanan wrote:
>
> Category has a method called l7dlog to help with parameterization and
> localization. But it doesn't quite do what I would like it to do.
>
> If I have a resource bundle that has the following entry
>
> ERROR_101=some error in the system
>
> then if I call
>
> l7dlog(Priority.ERROR, ERROR_101, null);
>
> the output would be
>
> "some error in the system"
>
> instead I would like it to print the error code along with the message,
> something like
>
> "ERROR_101: some error in the system"
>
> I know of two solutions to this...
> 1. change the resource bundle entry to
> ERROR_101=ERROR_101:some error in the system
> but, this is erorr prone, since developers could always enter the wrong id
> in the message.
>
> 2. Hack the Category class' l7dlog method to do customize it.
> In this case, every upgrade to log4j, I need to change my Category class,
> which could be a pain.
>
> Are there any other solutions to this?
>
> Help appreciated.
>
> Thanks
> Van
>
There is another possibility to achieve this (although it is not the
proper place to do it):
override protected void forcedLog(), which is called from l7dlog, and
manipulate your message string therein:
/**
This method creates a new logging event and logs the event
without further checks. */
protected
void forcedLog(String fqcn, Priority priority, Object message,
Throwable t) {
// message is "some error in the system"
// have a getKey() method
// squeeze the key in front of the original message
// or make a new string --> new_message
callAppenders(new LoggingEvent(fqcn, this, priority, new_message,
t));
}
HTH
Claus
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]