[logback-user] Logging depending on Class / Method

Nikolas Everett nik9000 at gmail.com
Mon Sep 20 16:24:03 CEST 2010


Why not make a logger just for method2?  Something like this might do it for
you:

public Class D{

        Logger logger = LoggerFactory.getLogger(D.class);
        Logger loggerForMethod2 = LoggerFactory.getLogger(*D.class + "
#method2"*);

        public void method1(){
                logger.info("method1");
        }

        public void method2(){
                logger.info("method2");
        }
}

On Mon, Sep 20, 2010 at 10:21 AM, <marc.baumgartner at degussa-bank.de> wrote:

> Hi all,
>
> is there a possibility to log depending on the class or method? For example
> I have the following scenario:
>
> package a.b.c
>
> public Class D{
>
>         Logger logger = LoggerFactory.getLogger(D.class);
>
>         public void method1(){
>                 logger.info("method1");
>         }
>
>         public void method2(){
>                 logger.info("method2");
>         }
> }
>
> I look for something like this in logback configuration:
>
> <logger name=*"a.b.c.D#method1"* level=*"INFO"* />
>
> <root level=*"WARN"*>
> </root>
>
>
> After calling method1 and method2 I would expect only the log entry of
> method 2.
>
> Is this possible?
>
> Thanks & regards,
> Marc
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-user/attachments/20100920/3cf45741/attachment.html>


More information about the Logback-user mailing list