我部署在 Tomcat 上的应用程序使用 log4j 编写日志文件。如果我删除该文件,则该应用程序不会重新创建它。我也尝试手动重新创建它,但它始终是空的。有什么方法可以删除日志文件(不是从应用程序中删除),在同一路径下创建一个同名的新日志文件,并且它可以由应用程序写入?
最佳答案
Is there any way to delete the log file (not from the app), create a new one in the same path with the same name, and that it can be written by the application?
没有。您需要让应用程序本身重新启动日志记录。
问题是 log4j appender 仍然有一个已删除文件的句柄,并将继续写入它......不知道它已被删除。
更好的方法是让应用程序本身负责“旋转”日志文件。看classes为一些想法实现 log4j Appender
接口(interface)。
关于java - Log4j 删除后不重新创建日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41700187/