Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 7. Accessing logs on your Thorntail application
7.1. Enabling logging Copier lienLien copié sur presse-papiers!
Each Thorntail fraction is dependent on the Logging fraction, which means that if you use any Thorntail fraction in your application, logging is automatically enabled on the INFO level and higher. If you want to enable logging explicitly, add the Logging fraction to the POM file of your application.
Prerequisites
- A Maven-based application
Procedure
Find the
<dependencies>section in thepom.xmlfile of your application. Verify it contains the following coordinates. If it does not, add them.<dependency> <groupId>io.thorntail</groupId> <artifactId>logging</artifactId> </dependency>
<dependency> <groupId>io.thorntail</groupId> <artifactId>logging</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you want to log messages of a level other than
INFO, launch the application while specifying thethorntail.loggingsystem property:mvn thorntail:run -Dthorntail.logging=FINE
$ mvn thorntail:run -Dthorntail.logging=FINECopy to Clipboard Copied! Toggle word wrap Toggle overflow See the
org.wildfly.swarm.config.logging.Levelclass for the list of available levels.
7.2. Logging to a file Copier lienLien copié sur presse-papiers!
In addition to the console logging, you can save the logs of your application in a file. Typically, deployments use rotating logs to save disk space.
In Thorntail, logging is configured using system properties. Even though it is possible to use the -Dproperty=value syntax when launching your application, it is strongly recommended to configure file logging using the YAML profile files.
Prerequisites
- A Maven-based application with the logging fraction enabled. For more information, see Section 7.1, “Enabling logging”.
- A writable directory on your file system.
Procedure
Open a YAML profile file of your choice. If you do not know which one to use, open
project-defaults.ymlin thesrc/main/resourcesdirectory in your application sources. In the YAML file, add the following section:thorntail: logging:
thorntail: logging:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure a formatter (optional). The following formatters are configured by default:
- PATTERN
- Useful for logging into a file.
- COLOR_PATTERN
- Color output. Useful for logging to the console.
To configure a custom formatter, add a new formatter with a pattern of your choice in the
loggingsection. In this example, it is calledLOG_FORMATTER:pattern-formatters: LOG_FORMATTER: pattern: "%p [%c] %s%e%n"pattern-formatters: LOG_FORMATTER: pattern: "%p [%c] %s%e%n"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure a file handler to use with the loggers. This example shows the configuration of a periodic rotating file handler. Under
logging, add aperiodic-rotating-file-handlerssection with a new handler.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Here, a new handler named
FILEis created, logging events of theINFOlevel and higher. It logs in thetargetdirectory, and each log file is namedMY_APP_NAME.logwith the suffix.yyyy-MM-dd. Thorntail automatically parses the log rotation period from the suffix, so ensure you use a format compatible with thejava.text.SimpleDateFormatclass.Configure the root logger.
The root logger is by default configured to use the
CONSOLEhandler only. Underlogging, add aroot-loggersection with the handlers you wish to use:root-logger: handlers: - CONSOLE - FILE
root-logger: handlers: - CONSOLE - FILECopy to Clipboard Copied! Toggle word wrap Toggle overflow Here, the
FILEhandler from the previous step is used, along with the default console handler.
Below, you can see the complete logging configuration section:
The logging section in a YAML configuration profile