java - 日志文件句柄如何设计比较好?
阿神
阿神 2017-04-17 13:23:27
0
3
753

写了一个异步服务器,用于处理网站的非实时性请求。目前每秒约写入10-100条日志,高峰时期可能写入约1000条日志。

我能想到的关于日志文件处理方法有下面几种,请问一般是如何实现的呢?

方法一:
每次写日志时获得文件句柄,写入后关闭。

方法二:
句柄作为单例,存在与整个程序生命周期,只有程序结束时才关闭。

方法三:
句柄作为单例,存在与整个程序生命周期,定期关闭重新打开。

阿神
阿神

闭关修行中......

reply all(3)
黄舟

Method 3 has been actually used in projects. Maybe my needs are slightly different from yours. The writing frequency of my logs generally does not exceed 10 entries/second, but the log files need to be saved on a daily basis and old files are deleted regularly (save logs of the past 7 days, etc.), so regular closing is a must~

迷茫

Method 2, try opening the handle again when an error occurs

PHPzhong

My question is, under Windows 2008, if the log handle is open, it cannot be copied and deleted.
This is very annoying. I hope I can view the log handle easily at any time. I don’t know how the first type of opening and closing frequency is very high, and how it affects the program and hard disk IO performance.

I haven’t used the log4cpp cplus log system yet, I don’t know what their design is!

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