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

On 17 July 2013 09:23, David Roussel <nabble@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@gmail.com Research Fellow: EPSRC Care Life Cycle Project http://www.southampton.ac.uk/clc

On 17 Jul 2013, at 10:23, Stuart Rossiter <stuart.p.rossiter@gmail.com> wrote:
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.
Stuart, maybe you picked up this habit from java.util.logging which only allows string names to be passed when creating a logger. I personally favour the "LoggerFactory.getLogger(MyClass.class)" form for the following reasons: 1) Typo avoidance - if I misspell the class name, then the IDE and compiler will complain 2) Tooling support - Find Usages, Rename Class refactorings will work without having to enable 'seach in strings' There is no .java stuffix, just the .class suffix, and it's not so ugly, in fact the IDE makes it a pretty colour! :-) David

On 17 July 2013 10:34, David Roussel <nabble@diroussel.xsmail.com> wrote:
There is no .java stuffix, just the .class suffix, and it's not so ugly, in fact the IDE makes it a pretty colour! :-)
I was confused because the poster's log extracts clearly show SLF4JConsoleTest.java being used as the name of the logger, when he used the basic getLogger(Class clazz) form in his code. No access to coding platform at the mo, so I'm posting 'blind' here! Stuart -- ________________________________ Stuart Rossiter stuart.p.rossiter@gmail.com

On 17 Jul 2013, at 11:09, Stuart Rossiter <stuart.p.rossiter@gmail.com> wrote:
There is no .java stuffix, just the .class suffix, and it's not so ugly, in fact the IDE makes it a pretty colour! :-)
I was confused because the poster's log extracts clearly show SLF4JConsoleTest.java being used as the name of the logger, when he used the basic getLogger(Class clazz) form in his code.
No access to coding platform at the mo, so I'm posting 'blind' here!
Sorry, you are right, my bad. The %file pattern is being used, and that outputs the name of the source file. And since the inner class is in the same source file as the outer class, the source file logged is the same. I've never used %file myself, as it's slow, and if you use one logger per class then you can infer the source file. David

On 17 July 2013 11:27, David Roussel <nabble@diroussel.xsmail.com> wrote:
The %file pattern is being used, and that outputs the name of the source file.
Ah yes, should have spotted that. Thanks. Stuart -- ________________________________ Stuart Rossiter stuart.p.rossiter@gmail.com Research Fellow: EPSRC Care Life Cycle Project http://www.southampton.ac.uk/clc
participants (2)
-
David Roussel
-
Stuart Rossiter