nullary LoggerFactory.getLogger method?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

nullary LoggerFactory.getLogger method?

Zack Sampson

Hey,

 

We’ve recently migrated from our own façade around log4j to SLF4J. One of the niceties we leave behind is a nullary getLogger call, kind of like so:

 

Logger _log = Logger.getLogger();

 

We use reflection to look at the stack and get the calling class’s name. We find this more convenient and consistent than manually specifying the name of the class.

 

Is there any reason SLF4J doesn’t support something like this?


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nullary LoggerFactory.getLogger method?

Jeff Jensen-2
Perhaps you can use "getClass()" for instance logging?

For my teams, I make an IDE macro (named "log") that auto-inserts this line at the cursor:
private final Logger log = LoggerFactory.getLogger(getClass());


On Mon, May 9, 2016 at 1:54 PM, Zack Sampson <[hidden email]> wrote:

Hey,

 

We’ve recently migrated from our own façade around log4j to SLF4J. One of the niceties we leave behind is a nullary getLogger call, kind of like so:

 

Logger _log = Logger.getLogger();

 

We use reflection to look at the stack and get the calling class’s name. We find this more convenient and consistent than manually specifying the name of the class.

 

Is there any reason SLF4J doesn’t support something like this?


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nullary LoggerFactory.getLogger method?

Gary Gregory
Hi,

But that does not work for static loggers. Do you always want to create or lookup one logger per instance?

Gary

On Mon, May 9, 2016 at 1:19 PM, Jeff Jensen <[hidden email]> wrote:
Perhaps you can use "getClass()" for instance logging?

For my teams, I make an IDE macro (named "log") that auto-inserts this line at the cursor:
private final Logger log = LoggerFactory.getLogger(getClass());


On Mon, May 9, 2016 at 1:54 PM, Zack Sampson <[hidden email]> wrote:

Hey,

 

We’ve recently migrated from our own façade around log4j to SLF4J. One of the niceties we leave behind is a nullary getLogger call, kind of like so:

 

Logger _log = Logger.getLogger();

 

We use reflection to look at the stack and get the calling class’s name. We find this more convenient and consistent than manually specifying the name of the class.

 

Is there any reason SLF4J doesn’t support something like this?


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user



--

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nullary LoggerFactory.getLogger method?

Hugo Garza
I like using Lombok's @Slf4j annotation for this

On Mon, May 9, 2016 at 3:45 PM, Gary Gregory <[hidden email]> wrote:
Hi,

But that does not work for static loggers. Do you always want to create or lookup one logger per instance?

Gary

On Mon, May 9, 2016 at 1:19 PM, Jeff Jensen <[hidden email]> wrote:
Perhaps you can use "getClass()" for instance logging?

For my teams, I make an IDE macro (named "log") that auto-inserts this line at the cursor:
private final Logger log = LoggerFactory.getLogger(getClass());


On Mon, May 9, 2016 at 1:54 PM, Zack Sampson <[hidden email]> wrote:

Hey,

 

We’ve recently migrated from our own façade around log4j to SLF4J. One of the niceties we leave behind is a nullary getLogger call, kind of like so:

 

Logger _log = Logger.getLogger();

 

We use reflection to look at the stack and get the calling class’s name. We find this more convenient and consistent than manually specifying the name of the class.

 

Is there any reason SLF4J doesn’t support something like this?


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user



--

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Loading...