Answer the question
In order to leave comments, you need to log in
Why doesn't log4j work on Tomcat?
Logging works fine in regular applications, normally saves a file with logs to the directory, but absolutely does not want to do this in an application on Servelet, a file with logs is not created at all.
import com.sun.java.accessibility.util.TopLevelWindowListener;
import org.apache.log4j.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* Created by Loligan on 06.04.2016.
*/
public class One extends HttpServlet{
{
Two.setLog("started");
}
static {
Two.setLog("connect");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Two.setLog("msg");
super.doGet(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Two.setLog("msg");
super.doPost(req, resp);
}
}
class Two{
{
setLog("started");
}
private static final Logger log = Logger.getLogger(One.class);
public static void setLog(String msg){
log.info(msg);
}
}
# Уровень логирования
log4j.rootLogger=INFO, file
# Апендер для работы с файлами
log4j.appender.file=org.apache.log4j.RollingFileAppender
# Путь где будет создаваться лог файл
log4j.appender.file.File=src//java//og_file.log
# Указываем максимальный размер файла с логами
log4j.appender.file.MaxFileSize=1MB
# Конфигурируем шаблон вывода логов в файл
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
I would start by adding the first line to the log4j config:
and looking at the log4j logs itself
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question