log4j2.properties file need to save in spring boot application

  1. Create a new file named log4j2.properties in the src/main/resources directory of your Spring Boot application.

  2. Open the log4j2.properties file and configure the desired logging settings using the Log4j 2 properties syntax.

Example configuration: ```properties status = error name = PropertiesConfig

property.filename = logs/app.log

appenders = console, file

appender.console.type = Console appender.console.name = STDOUT appender.console.layout.type = PatternLayout appender.console.layout.pattern = [%d{HH:mm:ss.SSS}] [%t] %-5level %logger{36} - %msg%n

appender.file.type = File appender.file.name = File appender.file.fileName = ${filename} appender.file.layout.type = PatternLayout appender.file.layout.pattern = [%d{HH:mm:ss.SSS}] [%t] %-5level %logger{36} - %msg%n

loggers = fileLogger

logger.fileLogger.name = com.example logger.fileLogger.level = debug logger.fileLogger.appenderRef.file.ref = File ```

Adjust the configuration based on your specific requirements.

  1. Save the log4j2.properties file.

  2. Add the required dependencies to your pom.xml file to include Log4j 2 in your Spring Boot application.

xml <dependencies> <!-- Other dependencies --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> <!-- Other dependencies --> </dependencies>

Make sure to exclude the default logging dependencies if needed.

  1. Ensure that your Spring Boot application is configured to use the log4j2.properties file for logging.

  2. If you are using Spring Boot 2.x, no additional configuration is required.

  3. For Spring Boot 1.x, you may need to specify the location of the log4j2.properties file in your application.properties or application.yml:

    properties logging.config=classpath:log4j2.properties

  4. Run your Spring Boot application, and Log4j 2 will use the specified log4j2.properties configuration for logging.