log4j with spring boot restful services
Java
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Properties>
<Property name="LOG_PATTERN">
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex
</Property>
</Properties>
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.example.log4j2demo" level="debug" additivity="false">
<AppenderRef ref="ConsoleAppender" />
</Logger>
<Root level="info">
<AppenderRef ref="ConsoleAppender" />
</Root>
</Loggers>
</Configuration>
<!-- Rolling File Appender -->
<RollingFile name="FileAppender" fileName="logs/log4j2-demo.log"
filePattern="logs/log4j2-demo-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<Pattern>${LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10MB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
package com.example.log4j2demo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Log4j2DemoApplication implements ApplicationRunner {
private static final Logger logger = LogManager.getLogger(Log4j2DemoApplication.class);
public static void main(String[] args) {
SpringApplication.run(Log4j2DemoApplication.class, args);
}
@Override
public void run(ApplicationArguments applicationArguments) throws Exception {
logger.debug("Debugging log");
logger.info("Info log");
logger.warn("Hey, This is a warning!");
logger.error("Oops! We have an Error. OK");
logger.fatal("Damn! Fatal error. Please fix me.");
}
}
<!-- Exclude Spring Boot's Default Logging -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Add Log4j2 Dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
Also in Java:
- Title
- how to add element to arraylist
- Category
- Java
- Title
- final variables in java
- Category
- Java
- Title
- initialize arraylist
- Category
- Java
- Title
- arraylist set method
- Category
- Java
- Title
- import
- Category
- Java
- Title
- read csv java android
- Category
- Java
- Title
- bootstrap center text vertically
- Category
- Java
- Title
- java string split underscore
- Category
- Java
- Title
- replaceall in java
- Category
- Java
- Title
- java code to get all leaf nodes of a xml
- Category
- Java
- Title
- how to format a datetime object to show date and time and milliseconds in java
- Category
- Java
- Title
- java pause program until key pressed
- Category
- Java
- Title
- java delay
- Category
- Java
- Title
- java treemap
- Category
- Java
- Title
- android foreground push notification
- Category
- Java
- Title
- changing double space to single in java script
- Category
- Java
- Title
- java script snippet for responsive
- Category
- Java
- Title
- java cmd install raspbian
- Category
- Java
- Title
- java 8 findany on null list
- Category
- Java
- Title
- download spring
- Category
- Java
- Title
- Please ensure that your JAVA_HOME points to a valid Java SDK. You are currently pointing to: /usr/lib/jvm/java-13-oracle
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- remove unused imports intellij
- Category
- Java
- Title
- How to create a 2d array in java
- Category
- Java
- Title
- for loop java
- Category
- Java
- Title
- money value commas java
- Category
- Java
- Title
- tolowercase java
- Category
- Java
- Title
- how to initialize an array in java
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- google translate
- Category
- Java
- Title
- java switch display panel
- Category
- Java
- Title
- Java nested array hashcode
- Category
- Java
- Title
- how to declare an array in java
- Category
- Java
- Title
- how to create a hashmap in java
- Category
- Java
- Title
- what is a method example in java
- Category
- Java
- Title
- date format in java
- Category
- Java
- Title
- java create clas
- Category
- Java
- Title
- jackson ignore values if empty
- Category
- Java
- Title
- java bigdecimal compareto
- Category
- Java
- Title
- how to check if in array java
- Category
- Java
- Title
- jsonobject to java object
- Category
- Java
- Title
- java stack methods
- Category
- Java
- Title
- bukkit java connect player to another server in bungeecord
- Category
- Java
- Title
- inheritance setter and getter in java
- Category
- Java
- Title
- java newinstance alternative
- Category
- Java
- Title
- how to find complement of a number in java
- Category
- Java
- Title
- java main method
- Category
- Java
- Title
- java fullscreen jframe
- Category
- Java
- Title
- java how to define a function
- Category
- Java
- Title
- java put a char array into a string
- Category
- Java
- Title
- file to image javafx
- Category
- Java
- Title
- add element to stack java
- Category
- Java
- Title
- linux command to see all the java version installed
- Category
- Java
- Title
- read integer input java
- Category
- Java
- Title
- numberformatexception
- Category
- Java
- Title
- java windowbuilder full screen
- Category
- Java
- Title
- how to make a char uppercase in java
- Category
- Java
- Title
- biginteger in java
- Category
- Java
- Title
- JOptionPane with drop down list java
- Category
- Java
- Title
- java stack empty
- Category
- Java
- Title
- gravity in java
- Category
- Java
- Title
- java literals w3schools
- Category
- Java
- Title
- osmdroid offline map does not show
- Category
- Java
- Title
- int java
- Category
- Java
- Title
- java mouseevent
- Category
- Java
- Title
- android how to split string
- Category
- Java
- Title
- java get current date without time
- Category
- Java
- Title
- bukkit scheduled task
- Category
- Java
- Title
- The specified child already has a parent. You must call removeView() on the child's parent first
- Category
- Java
- Title
- lopp array java
- Category
- Java
- Title
- android dynamically create layer-list with item and shape site:stackoverflow.com
- Category
- Java
- Title
- toString convert to long
- Category
- Java
- Title
- string isEmpty java
- Category
- Java
- Title
- java script print date in YYYY-MM-DD format
- Category
- Java
- Title
- java sleep in code
- Category
- Java
- Title
- java method overriding
- Category
- Java
- Title
- how to check the end of a string java
- Category
- Java
- Title
- java rest client response json
- Category
- Java
- Title
- java console text color
- Category
- Java
- Title
- java check if element exists in array
- Category
- Java
- Title
- LocalRegistry java rebind() java8
- Category
- Java
- Title
- set iteration java
- Category
- Java
- Title
- simple calculator program in java
- Category
- Java
- Title
- integer max value java
- Category
- Java
- Title
- java final meaning
- Category
- Java
- Title
- getordefault java
- Category
- Java
- Title
- difference between java and javax
- Category
- Java
- Title
- splitting using regex java
- Category
- Java
- Title
- remove first character from string
- Category
- Java
- Title
- .length array java
- Category
- Java
- Title
- create jdbc connection in java
- Category
- Java
- Title
- init cap java
- Category
- Java
- Title
- raise number to power java
- Category
- Java
- Title
- java valeur absolue
- Category
- Java
- Title
- java size of stack
- Category
- Java
- Title
- enhanced for loop java
- Category
- Java
- Title
- run java program maven
- Category
- Java
- Title
- continue in java
- Category
- Java
- Title
- testing the web layer without authentication spring
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java