Add file $PORJ_HOME/src/main/resources/vertx-default-jul-logging.properties:
handlers = java.util.logging.FileHandler java.util.logging.ConsoleHandler
java.util.logging.SimpleFormatter.format = %1$tF %1$tT.%1$tL %4$s %5$s [%2$s %3$s %6$s]%n
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.pattern = logs/bomserver.log
java.util.logging.FileHandler.level = INFO
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 5
Note that the directories you defined in FileHandler.pattern must already exists, or an exception raised when app started.
In the class you want to add a logger, for example, MyApp.groovy, add the following codes into the class body:
private static final Logger LOGGER = Logger.getLogger(
Thread.currentThread().getStackTrace()[0].getClassName());
In the method body you want to log, add the following codes:
LOGGER.info("Starting server at port ${config['server.port']}")
Never forget adding import java.util.logging.Logger
in the class.
References
About logging utility:
Log format(defined in java.util.logging.SimpleFormatter.format): section Format String Syntax in java.util.Formatter.
About file handler:
- https://stackoverflow.com/questions/8342336/how-to-set-maximum-number-of-rolls-and-maximum-log-size-for-tomcat
- https://stackoverflow.com/questions/8248899/java-logging-how-to-redirect-output-to-a-custom-log-file-for-a-logger