[logback-user] class name is displayed incorrectly for java inner classes

Stuart Rossiter stuart.p.rossiter at gmail.com
Wed Jul 17 11:23:16 CEST 2013


On 17 July 2013 09:23, David Roussel <nabble at diroussel.xsmail.com> wrote:

> Andy,
>
> The name of the logger is set when the logger is created form the
> LoggerFactory.  You are creating LOG in your outer class.  Try creating
> another logger in your inner class.
>

Yes, it is slightly subtle that the loggers just have the name you pass to
them: they don't 'know' the class structure of what's calling them, and we
don't want them to since we might want our own arbitrary set of loggers
where each covers some specific set of classes (say). Even though you are
using the getLogger(Class clazz) form, it still just generates a logger
name, which multiple classes could reuse if they wanted to (by passing that
name in their Logger setup code).

BTW (general question to the mailing list): this code suggests that the
getLogger(Class clazz) form sets the logger name using the source file name
(e.g., SLF4JConsoleTest.java here, cf. SLF4JConsoleTest). I've always used
the getLogger(String name) form, passing
SLF4JConsoleTest.class.getCanonicalName(), or getSimpleName() if I don't
want the full name. (It might even be that I changed to that because of
this ugly .java suffix, though I can't explicitly remember that.)

Is there a reason for that? If it's to link to the file producing it
(rather than the class), that doesn't seem very useful without a path.

Apologies if this is stated somewhere obvious in the manual.

Stuart

-- 
________________________________
Stuart Rossiter
stuart.p.rossiter at gmail.com

Research Fellow: EPSRC Care Life Cycle Project
http://www.southampton.ac.uk/clc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20130717/5c49c850/attachment.html>


More information about the Logback-user mailing list