How to use java LOGGER

Asked

Viewed 2,606 times

2

I set up the 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);

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

It’s good practice to use the Logger in 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");

1 answer

4

I use slf4j’s Loggerfactory.

For each class:

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

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

Ps: "{}" reports a variable value in the LOG.

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

or

LOGGER.error("error whathever");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.