Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the logger of a class in a static context?

Tags:

java

logging

I'm trying to recieve the logger for my class:

public static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(this);

But using "this" there causes "Cannot use this in a static context" error.

Anyone know how to fix this?

EDIT: I must be able to access the logger from all classes in my program, so it must be public.

like image 673
stommestack Avatar asked Nov 22 '12 18:11

stommestack


1 Answers

Notice I changed modifier from public to private:

public class FooBar {

    private static final Logger log = Logger.getLogger(FooBar.class);

    //or (if you are using java.util.logging):

    private static final Logger log = Logger.getLogger(FooBar.class.getName());


}
like image 181
Tomasz Nurkiewicz Avatar answered Nov 14 '22 22:11

Tomasz Nurkiewicz