异步log to file
1. 启动一个多线程,维护一个List列表。List中存放的是需要log的字符串。早期用Vector来考虑同步的问题,甚至可以包装Vector。加入wait/notify机制。
2. 主程序启动时打开文件,主程序结束时关闭文件。其他还有异常,rotate file时也需要关闭文件。
// Open the file output stream
logOutputStream = new FileOutputStream(this.fileName);
// Create the print writer output stream
logPrintWriter = new PrintWriter(logOutputStream);
3. rotate file 可以用一个计划任务定时完成(不考虑文件大小)。先关掉filename,改为备份文件名字。再打开filename
4. 写日志时, 需要 logPrintWriter.flush();
不知跟log4j有些什么差别?