Answer the question
In order to leave comments, you need to log in
Why is it not saving logs to a log4j file?
I created an MVC project in IDEA, connected log4j via pom.xml, added simple logging but does not write to the file:
pom.xml:
<?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("Order placed");
log.info("Order completed. This is an informational message.");
addToCard();
}
private void addToCard() {
System.out.println("Item added to cart");
log.warning("This is an error message (probably)");
}
}
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
Answer the question
In order to leave comments, you need to log in
A little embarrassing
src/main/java/test.class
public class test {
public static OrderLogic logic;
public static void main(String[] args) {
logic = new OrderLogic();
logic.doOrder();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question