How to use LOGGER in java

2

I configured Logger in my main class.

public static final Logger LOGGER = Logger.getLogger(DashBoard.class.getName());

and I'm using it this way:

LOGGER.log(Level.SEVERE, "Error occur in FileHandler.", exception);

But now I wanted to use the same log file in other classes.

Is it good practice to use Logger this way?

- > config.class

// devido a ter definido como static tenho acesso nas outras classes deste modo 
DashBoard.LOGGER.log(Level.INFO, "Loading... FxmlQualidade.fxml");
    
asked by anonymous 08.02.2018 / 11:14

1 answer

3

I use the LoggerFactory of slf4j.

For each class:

private static final Logger LOGGER = LoggerFactory.getLogger(MinhaClasse.class);

To use (I think the most used are info, error, debug):

Ps: "{}" informs a variable value in LOG.

LOGGER.info("total time {} seconds", total);

or

LOGGER.error("error whathever");
    
09.02.2018 / 11:41