0

My current project taking Log4j for logging output but when it is deployed on websphere 7 it seems the logging file is always occupied by the server hence Log4J cannot close it and open a new file. Current log file can expand to 1.5 Gb if on DEBUG level. I went through a few online tutorials but didn't get a solid solution. So I open this thread for any opinion or experience on making log4J works on WS 7.

Current log4J is on 1.2.15, and the project is a plain POJO/JSP application without other containers(like Spring, I do have another project with same issue on Spring/tomcat, will open in another thread). And here is the log4j.properties:

log4j.rootCategory=INFO, ROL
#
# Rolling File Appender
#
log4j.appender.ROL=org.apache.log4j.RollingFileAppender
log4j.appender.ROL.Encoding=UTF-8
log4j.appender.ROL.File=C\:\\Logs\\AppOut.log
log4j.appender.ROL.MaxFileSize=10000KB
log4j.appender.ROL.MaxBackupIndex=10
log4j.appender.ROL.layout=org.apache.log4j.PatternLayout
log4j.appender.ROL.layout.ConversionPattern=%d -- %p -- %c -- %m%n

But this configuration just doesn't make log file roll over.

UPDATE:

It seems like each time when I try to remove the log file after stop the application(not the server), it is always saying "the file is opened by another application" which only refers to Websphere. I can guarantee that there is no other application is opening the log file. The only way to release lock on it is stop the application server.

Thanks in advance for any ideas.

Dreamer
  • 7,333
  • 24
  • 99
  • 179
  • Is your logging going to AppOut.log or to WebSphere's SystemOut.log? Are you saying that WebSphere's logging is going to your application log file? (I'm trying to understand the statement "logging file is always occupied by the server".) – dbreaux Nov 10 '12 at 21:07
  • @dbreaux Thank you and apologize the late feed back. it output to AppOut.log instead of Websphere's SystemOut.log and yes it is going to output to application log file. But still each time when I try to remove the log file after stop the application, it is always saying "the file is opened by another application" which only refers to websphere. – Dreamer Nov 11 '12 at 16:08
  • Ok, WebSphere's own logging is going to your AppOut.log, not to SystemOut.log, which would be consistent with the file being locked even with the application stopped. Are you using parent_last classloading? – dbreaux Nov 12 '12 at 16:42
  • @dbreaux That is correct. We put parent_last in websphere configuration to put application lib the first priority. – Dreamer Nov 12 '12 at 20:35
  • 1
    I'm not surprised parent_last is causing WebSphere's logs to go to your application log file. Do you need parent_last for some other reason, or only for logging? I try to avoid parent_last at all costs, but I realize it's not always possible. There are ways to split the logging with parent_first, but I don't know how to get WebSphere's logs out of yours with parent_last. See http://stackoverflow.com/questions/8131529/websphere-all-logs-are-going-to-systemout-log/ – dbreaux Nov 12 '12 at 22:12
  • Are you on Windows? I'm seeing the exact same problem on WAS7, Win 2008. In our Unix environments, we don't have this issue. Still looking for a solution for this issue myself. When I stop only the application, and then restart it, it seems that log4j is unable to roll my logs. I get the following error in SystemOut: log4j:ERROR Failed to rename [/logs/app/xxxx.log] to [/logs/app/xxx.log.2012-12-04-09] – Erich Musick Dec 04 '12 at 16:44
  • @Erich Musick Yes the issue happens on windows server. I guess it is not the issue of the platform but the WAS7 windows release doesn't work well with Log4J. Please check Albert T. Wong's answer to this thread, currently I haven't find any working solution to this issue yet..But that's really make me curious how many applications are running on WS with Log4J in industry? Do they all have this issue? It is grateful if you have any findings to share.. – Dreamer Dec 05 '12 at 20:20

1 Answers1

2

we use was 7 (with portal server 6.1 on top). (We wrap our calls to the logger using the sl4j lbrary, but I don't think that is relevant to the problem here). can't really see any major difference, other than we don't set the root category, and we explicitly set the additivty to false.

Below is part of our config (showing just one of our appenders) which works just fine and rolls the logs every 10MB as expected. Perhaps it's something configured in WAS itself - I'm not a WAS admin expert and didn't install WAS myself but could ask one of our admins on Monday if you haven't solved it.

log4j.logger.com.xxx.protection=TRACE, A1
log4j.additivity.com.xxx.protection=false

# other appenders excluded

log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=${LOG_ROOT}/applLogs/ui_and_business_logic.log
log4j.appender.A1.MaxFileSize=10MB
log4j.appender.A1.MaxBackupIndex=10
log4j.appender.A1.Append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %p %t %c MSG: %m%n
Steve Atkinson
  • 1,219
  • 2
  • 12
  • 30
  • Thank you for the assistance and sorry about the late feedback. Can I ask you about the version of the log4j running on your application? Also I have update the original post and could you please help to try removing the latest log file after stop the application(but don't stop the application server)? I am trying to verify whether the WAS on your end is going to put a lock on the log file even the application stops. Thanks again. – Dreamer Nov 11 '12 at 16:15
  • you can't remove the log file altogether if WAS is running, what we do with system,out and app logs is open them in a text editor and select all contents (ctrl A) and hit delete and then save - so you can replace the contents of the file but not remove the file iteself. However, the rolling still works. – Steve Atkinson Nov 12 '12 at 18:21