问题
We are using the Windows installation of Tomcat 6. By default, the log4j output for our app goes to the ${catalina.base}/logs/stdout_.log file. This log file only rolls over when we restart Tomcat, and the file name always includes the date.
I would prefer it to behave like a DailyRollingFileAppender, where it renames the file when it rolls over... that way I can just open Notepad++ and see today's logs, since Notepad++ will remember that I opened that same file yesterday. :)
I know I can just create another appender in log4j, but I would end up with the stdout.log and another log file, and I'm afraid there would be a minor performance hit for logging to both files. I've tried adding swallowOutput=true to my context.xml but I still get all logging in stdout.log. Any ideas?
回答1:
Have you tried the steps outlined in Logging in Tomcat? If you follow the steps you'll end up with log4j.properties in the lib directory that you can customize to your heart's content.
回答2:
The biggest performance hit is when preparing objects that you want to log (you know, when you do logger.info(" operating on " + myObject.toString + " bla bla bla" )
then doing myObject.toString()
has the biggest cost). If you already have them than loggin to file is not a problem. And log4j is really well balanced and optimized, it uses buffers to write logs, so it do not make too frequent calls to file system.
Just create another appender, you will have a differentation from tomcat logs and your appilcation logs. How many logs do you have? A 1GB a day or more that you are afraid of performance loss? Don't assume anything before testing it. Just set-up, and do some kind of performance test.
来源:https://stackoverflow.com/questions/2015273/can-you-make-the-tomcat-6-stdout-log-file-behave-like-a-log4j-dailyrollingfileap