-1

As the title says, I have a Logger object logger, in a class classname the definition of classname contains a vararg String v. If v does exist, logger should be named that, else it should have a default. How should I do this? My code:

final Logger logger=null;
    if(globalLogger!=null){
        logger.getLogger(globalLogger);
    }
    else{
      logger.getLogger(ImportThread.class.getName());
    }

This returns:The static method getLogger(String) should be accessed in a static way. Is this possible? If not, how should I go about this?

2 Answers2

0

You should specify which Logger class you are using. From the current info it seems to me the Logger logger variable should be static

static final Logger logger=null;

Note sure about the rest of the code but this should at least fix the "should be accessed in a static way" issue

suvartheec
  • 3,484
  • 1
  • 17
  • 21
0

access it statically means you call it as method of the class:

Logger logger=null;

if(globalLogger!=null){
    logger = Logger.getLogger(globalLogger);
} else{
  logger = Logger.getLogger(ImportThread.class.getName());
}

In your code, you did not use what Logger.getLogger() returned, I changed to an assignment; with this code you cannot make it final, because you cannot reassign a final variable.

P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66