java - 日志系统能不能保证日志在1min内写到磁盘上
高洛峰
高洛峰 2017-04-17 14:32:54
0
2
856

日志系统,如log4j或者glog等等有没有对于日志落到磁盘上的时间有没有什么保证?如何实现日志系统能在1min内将日志写到磁盘上。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
洪涛

No, in order to improve performance, memory buffering and disk buffering technology must be used.

Ty80

If you have requirements on the time it takes to spend on your hard drive, you may need to write it yourself;
Just like the fprintf we usually use for output, for performance reasons, the functions of the runtime library are buffered (the cache is usually around 4K, but not necessarily); buffering can reduce the number of system calls; you may adjust fprintf several times , there will be one write call to actually write to the hard disk;
If you implement it yourself, for real-time considerations, directly use the system call interface write() to record logs;
If there is a buffer tolerance of 1 minute, you can use fprintf when writing logs, but call fflush() once every minute to force the logs to fall to the hard disk;
PS: If there is such a strong flash interface on log4j, you can check the information;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template