Browse Source

feat: working with log4j 2.14.1

master
QuentinN42 9 months ago
parent
commit
85415be92b
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 2
      Makefile
  2. 11
      log4j2.xml
  3. 11
      pom.xml
  4. 13
      src/main/java/com/project/Main.java

2
Makefile

@ -9,4 +9,4 @@ build:
mvn package
run:
java -jar target/project-1.0.jar
clear && java -jar target/project-1.0.jar

11
log4j2.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} – %msg%n" />
</Console>
</Appenders>
<Loggers>
<logger name="Main" level="TRACE" />
</Loggers>
</Configuration>

11
pom.xml

@ -12,9 +12,14 @@
</properties>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
<build>

13
src/main/java/com/project/Main.java

@ -3,23 +3,22 @@ package com.project;
import java.util.*;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Main
{
static Logger log = Logger.getLogger("Main");
static final Logger logger = LogManager.getLogger("Main");
public static void main( String[] args )
{
BasicConfigurator.configure();
logger.error("Started app !");
Scanner sc=new Scanner(System.in);
while (true)
{
System.out.print("> ");
String s=sc.nextLine();
log.info("User input : " + s);
logger.error("User input : " + s);
}
}
}

Loading…
Cancel
Save