简体   繁体   中英

Java Servlet/ How to write the logs(log.debug and log.error entries) written in the server console to a separate txt file?

This is my first java servlet so I would be glad if you can help me and tell me what to do in details :) I can see my program's logs in server console but I need to copy all logs including log.debug and log.error entries to a txt file and later send the txt file via email.

I have to define the directory/file for the logs. I have managed this for a regular java program by adding log4j.xml under src folder so I could set the directory in it, it worked, it is writing logs to a txt file created. But I do not know how to do it for the servlet version of my program. How can I set the directory for logs in the servlet and write logs to a specific txt file?

使用log4j并配置一个FileAppender

You could use log4j too with servlets. You just have to add your log4j.xml in the folder YOURWEBAPP/WEB-INF/classes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM