How to register in singleum element?

I am using enum singleton, but logging is difficult. It:

public enum Foo {
  INSTANCE;

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

  ...
}

The logger is created in such a way that I would create a logger for a regular Java class, but of course I get the following error:

Foo.java: illegal reference to static field from initializer 

Is there an equivalent way to enter enum enumeration lists?

+5
source share
3 answers

In response to your question, just make a static log ...

By the way, I believe that the standard practice of using a static registrar is even for object instances. In other words, the registrar is in the classroom; all objects use static registrar links.

Cm

http://logging.apache.org/log4j/1.2/manual.html

...

+15

:

Logger.getLogger(Foo.class.getName()).info("log info");
+3

: : logger(). debug (...)

private static Logger logger()
{
    if(logger == null)
    {
        logger = Logger.getLogger(AnEnum.class);
    }

    return logger;
}

/** Logger **/
private static Logger logger;
+2
source

All Articles