<?xml version="1.0" encoding="UTF-8"?>
4.0.0log4jteachlog4jteach1.0-SNAPSHOTlog4jlog4j1.2.17
public class OrderLogic{
private static final Logger log = Logger.getLogger(String.valueOf(OrderLogic.class));
public void doOrder(){
System.out.println("Заказ оформлен");
log.info("Заказ оформлен. Это информационное сообщение.");
addToCard();
}
private void addToCard() {
System.out.println("Товар добавлене в корзину");
log.warning("Это сообщение ошибки (походу)");
}
}
public class test {
public static OrderLogic logic;
public static void main(String[] args) {
logic = new OrderLogic();
logic.doOrder();
}
}
log4j.rootLogger=DEBUG, stdout, file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/myapp.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
src/main/java/test.class
public class test {
public static OrderLogic logic;
public static void main(String[] args) {
logic = new OrderLogic();
logic.doOrder();
}
}
log4j.appender.file.File=${catalina.home}/logs/myapp.log