[slf4j-dev] [PATCH] allow passing of objects through jcl-over-slf4j
Ceki Gulcu
listid at qos.ch
Tue Sep 30 11:37:12 CEST 2008
Hello Robert,
Even if it solved your specific problem, your patch would complicate
jcl-over-slf4j's code for everyone else. Moreover, the SLF4JLocationAwareLogger
class also converts objects into strings, meaning that the same type of test
would need to be propagated to that class as well.
From what I could gather, by migration, you mean replacing commons-logging.jar
with jcl-over-slf4j.jar, right? Presumably, you log with metadata in your own
code (as in, code you control). Have you considered invoking the SLF4J API directly?
Regards,
Robert Varga wrote:
> Hi,
>
> we are considering migration of a major project to SLF4J -- but cannot
> do so due to what seems to be a limitation of jcl-over-slf4j.
>
> Our project uses a combination of JCL and log4j: we use JCL in the code,
> and wire the messages via log4j to a custom appender. The users wrap
> messages in a container object along with a bit of metadata, which the
> appender then picks up and uses the metadata to act on the message. The
> entire scenario looks roughly like:
>
> public class Metadata {
> public Metadata(...) {
> ...
> }
> }
>
> public class Message {
> final Metadata metadata;
> final String message;
>
> public Message(final Metadata metadata, final String message) {
> this.metadata = metadata;
> this.message = message;
> }
>
> Metadata getMetadata() {
> return metadata;
> }
>
> String toString() {
> return message;
> }
> }
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> public class User {
> protected final Log log = LogFactory.getLog(getClass());
> protected static final Metadata SOME_METADATA = new Metadata(...);
>
> void someMethod() {
> log.debug(new Message(SOME_METADATA, "Some message"));
> }
> }
>
> import org.apache.log4j.AppenderSkeleton;
> public class Appender implements AppenderSkeleton {
> public void append(final LoggingEvent event) {
> final Object msg = event.getMessage();
> if (msg instanceof Message) {
> final Metadata = ((Message)msg).getMetadata();
> ...
> } else {
> ...
> }
> }
> }
[snip]
> Robert
--
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
More information about the slf4j-dev
mailing list