Discussions

Web tier: servlets, JSP, Web frameworks: Log4j + Struts

  1. Log4j + Struts (4 messages)

    Dear all, I am trying to incorporate log4j into my Struts application. However, when I deploy and execute the application, I am not receiving any output to the console or the file that I defined in my log4j.properties file. I have included what I take to be the necessary files and their relative location to diagnose this issue. Any thoughts would be appreciated. log4j.properties: /WEB-INF/log4j.properties (I have also tried to include the log4j.properties files in the /WEB-INF/classes folder, but no dice.) log4j.rootLogger=DEBUG, stdout, rolling log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n log4j.appender.rolling=org.apache.log4j.RollingFileAppender log4j.appender.rolling.File=PMISOutput.log log4j.appender.rolling.MaxFileSize=1000KB log4j.appender.rolling.MaxBackupIndex=1 log4j.appender.rolling.layout=org.apache.log4j.PatternLayout log4j.appender.rolling.layout.ConversionPattern=%d{ABSOLUTE} - %P %C - %m%n Action Which Uses the Logging Mechanism: import org.apache.log4j.*; import javax.servlet.http.*; import org.apache.struts.Globals; import org.apache.struts.action.*; import xxx.xxx.xxxxxxxx.xxxxxxxxx.utils.Constants; import xxx.xxx.xxxxxxx.xxxxxxxxxx.xxxxx.UserViewForm; /** * Action for the Main Page. */ public class AccountMaintMain extends Action { static Logger logger = Logger.getLogger(AccountMaintMain.class); public ActionForward execute(ActionMapping map, ActionForm form, HttpServletRequest x, HttpServletResponse y) throws InvalidSFSessionException, Exception { logger.info("Got into AccountMaintMain."); String username = ((UserViewForm)form).getUsername(); String sfSessionId = ((UserViewForm)form).getSunflowerSession(); logger.info("The username is: " + username); logger.info("The sfSessionId is: " + sfSessionId); logger.info("Exiting the AccountMaintMain."); return map.findForward(Constants.SUCCESS_KEY); } } If there are any other files that you require to offer a suggestion, please advise. Bests, -h
  2. Sorry, but I forgot to include the platform and version of the software that I am using. platform: Windows 2000 struts version: 1.1 tomcat version: apache-tomcat-5.5.20 log4j version: log4j-1.2.14 Thanks again.
  3. if for example your class AccountMaintMain is in package com.vanitysoft.myapp.structs.action.AccountMaintMain add this to your log4j properties file. log4j.logger.com.vanitysoft.myapp.structs.action = DEBUG
  4. Re: Log4j + Struts[ Go to top ]

    Other than having incorrect character in the last line of your log4j.properties there seem to be no problems with it. I tried it in a simple standalone application and it worked fine. What I can suggest is that based on Default Initialization Procedure you try to see what the following line returns somewhere in your application: org.apache.log4j.helpers.Loader.getResource("log4j.properties") It might be that you have duplicates in your classpath.
  5. Re: Log4j + Struts[ Go to top ]

    try adding this static initializer at the begining of your class. static{ org.apache.log4j.BasicConfigurator.configure(); } Move the logging aspect to some utility class where it would ve initialized properly using this code segment with "Default Initialization Procedure". Keep rocking, Rohitdev