defining a private logger in a class


I used to define private class loggers like this.

class MyClass {

    private static final Logger logger = Logger.getLogger(
        MyClass.class.getName());
}

Nothing’s wrong, anyway. Even re-factoring problems, such as renaming the class, have been gone since I started using IDEs.
And yet, here comes a new way which could be said somewhat more portable with Java 7.

class MyClass {

    private static final Logger logger = Logger.getLogger(
        MethodHandles.lookup().lookupClass().getCanonicalName());
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s