L
L
Loligan2016-02-23 10:14:50
Java
Loligan, 2016-02-23 10:14:50

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

src/main/java/OrderLogic.class :
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)");
}
}

src/main/java/test.class
public class test {
public static OrderLogic logic;
public static void main(String[] args) {
logic = new OrderLogic();
logic.doOrder();
}
}

src/main/resources/log4j.properties
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

1 answer(s)
S
sirs, 2016-02-23
@sirs

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();
}
}

and than
Do you launch your application from the console, or do you pack it into a war file, for example, and deploy it to Tomcat?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question