开发者_如何学编程
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this questionI have a problem with Alfresco. It genarates the log file every day. i want to delete the log file automatically based on date. My server is installed in windows.
can you provide any suggestions on this one.
Alfresco is using DailyRollingFileAppender
and it is configured to roll log file daily.
###### File appender definition #######
log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=alfresco.log
log4j.appender.File.Append=true
log4j.appender.File.DatePattern='.'yyyy-MM-dd
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
Instead you can use RollingFileAppender
which rolls log files when it reaches a certain size and with this appender you can also define the maximum number of backups.
log4j.appender.File=org.apache.log4j.RollingFileAppender
log4j.appender.File.MaxBackupIndex=10
...
...
According to the configuration above the appender stores only the last 10 backups. BTW it is also more secure than DailyRollingFileAppender
.
According to log4j javadoc;
DailyRollingFileAppender has been observed to exhibit synchronization issues and data loss.
the best way is to write your own little utility and register it as a "scheduled task" to run at a pre-defined time in the day.
you can register a service too, but i feel that'll be an overkill.
I suggest that you decrease your logging level as much as you can. There is a log4j.properties file in each of alfresco's apps (alfresco/WEB-INF/classes/log4j.properties and share/WEB-INF/classes/log4j.properties) - logging is noted to affect the performance of alfresco.
Also, you should be able to disable logging completely.
Please see http://www.autohotkey.com/forum/topic43254.html Its providing one simple tool to delete logs. Just use it.
精彩评论