Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 TailerListener API 来监控日志文件。如果进程开始,它工作正常。如果我们重新启动 TailerListener,ii 将监控比此进程启动时间更早的日志。有什么办法可以避免这种情况。
提前致谢。
您的文件是否正在轮换?看看下面是否是您要问的,因为我以前遇到过这个问题。轮换文件时,默认行为似乎是从整个日志文件中吐出所有日志消息,而不仅仅是新的日志消息。所以我的问题是,如何在 TailerListener 中覆盖 fileRotated() 或更改行为以避免再次滚动整个日志文件(旧消息和新消息)?
File在java中有一个lastModified()方法。在创建 之前Tailer,请检查它。
File
lastModified()
Tailer