如果可以,考虑一下log4j什么都不用自己做,不过正如楼上说的线程还是进程?现成应该是没有问题的。进程不知道确切的是否可以,不过我启动两个WEB应用,把日志记录在同一个文件里面好像是可以的。

解决方案 »

  1.   

    Normally the "%u" unique field is set to 0. However, if the FileHandler tries to open the filename and finds the file is currently in use by another process it will increment the unique number field and try again. This will be repeated until FileHandler finds a file name that is not currently in use. 
    这段话说得很清楚啊。如果一个filehandler试图操作正在被另外一个filehandler操作的文件,那么它会重试直到成功取得文件的操作权(即该文件当前不被使用)所以应该每问题的,可能你的程序或者log的设定有问题。
      

  2.   

    是进程。it will increment the unique number field and try again所以,它会先生成一个文件 如test.log.1,然后再试。当然 能试通。
    我就是不想让它生成test.log.1这个文件。