You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by as...@polaris.co.in on 2003/06/13 11:44:45 UTC

RE: debugging in struts Solved

Hi,
To share with you
At last done.  I had removed the  commons-logging.jar which was wrong.
Now I am getting  the logs in my file from struts api.

Thanks.
/Ashwani



                                                                                                                       
                    "Hariharan"                                                                                        
                    <hariharan@medico        To:     <as...@polaris.co.in>                                     
                    msoft.com>               cc:                                                                       
                                             Subject:     RE: debugging in struts                                      
                    06/12/2003 06:26                                                                                   
                    PM                                                                                                 
                    Please respond to                                                                                  
                    hariharan                                                                                          
                                                                                                                       
                                                                                                                       






Ok I guess some tomcat expert needs to Ans. this one.
Iam using Oracle 9iAS....

-Hari


-----Original Message-----
From: ashwani.kalra@polaris.co.in [mailto:ashwani.kalra@polaris.co.in]
Sent: Thursday, June 12, 2003 3:26 PM
To: hariharan@medicomsoft.com
Subject: RE: debugging in struts



hi,
Thanks for this.
I am doing the same way with slight difference. First is that I am using
xml file log4j_config.xml instead of properties file. Second is that I am
not initializing it in my servlet. I am doing this by setting the property
-Dlog4.configuration=<<log4j_config.xml >>. in Tomcat
Things are working fine when I give my own debugging statements , but the
log from the struts api is going(what ever is coming ) is going to tomcat
log instead of file specified by me in log4j_config.xml . I think Tomcat
logging is clashing with mine.
I just check at the list if somebody is doing on tomcat.  Which server you
are using ?











                    "Hariharan"
                    <hariharan@medico        To:
<as...@polaris.co.in>
                    msoft.com>               cc:
                                             Subject:     RE: debugging in
struts
                    06/12/2003 12:30
                    PM
                    Please respond to
                    hariharan







Sure ,

apart from the basic log4j setup i have done following things..
you need three things to do .

make following entries in your web.xml file
STEP-1
------
            <servlet>
               <servlet-name>log4j-init</servlet-name>
               <servlet-class>com.medicom.common.Log4jInit</servlet-class>

               <init-param>
                 <param-name>log4j.properties</param-name>

<param-value>WEB-INF/classes/log4j.properties</param-value>
               </init-param>

               <load-on-startup>1</load-on-startup>
             </servlet>

STEP-2
-----
I have com.medicom.common.Log4jInit servlet you can change the package name
if u want.
here is the content of thse init servlet

/*
 * Created on Jun 7, 2003
 *
 * prototype for DMC using struts
 * dmc_prototype
 * $Id:$
 */
package com.medicom.common;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.PropertyConfigurator;


/**
 * @author Administrator
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class Log4jInit extends HttpServlet {
           public void init(){
                     String prefix = getServletContext().getRealPath("/");
                     String file = getInitParameter("log4j.properties");

                     if (file != null){
                               System.err.println("using log file" + prefix
+ file);
                               PropertyConfigurator.configure(prefix +
file);
                     }
           }

           public void doPost(HttpServletRequest req, HttpServletResponse
res)
           throws ServletException, IOException
           {

           }

           public void doGet(HttpServletRequest req, HttpServletResponse
res)
           throws ServletException, IOException
           {

           }

}

STEP-3
------
Here is the content of my log4j.properties file
that I have saved under WEB-INF/classes directory of my orion server

# Start of log4j.properties file
# This defines the logging level for the rootLogger. It is not required
# if you are going to keep the level at debug as the rootLogger by default
# is at the debug level. The value after the comma is the appender for the
# root and we have given it the name R
#
log4j.rootLogger=debug, R

#
# For this example, we are just going to log to the console
#
log4j.appender.R=org.apache.log4j.ConsoleAppender

#
# When logging using the ConsoleAppender, the following value tells how and
# what to log. The SimpleLayout simply logs the level of the message and
# the message itself.
#
log4j.appender.R.layout=org.apache.log4j.SimpleLayout


#
# In this configuration we are going to use MDC to log messages for a
special
# category that we define in the GetCommentsServlet
# So first define the level of logging for the category and add a new
appender
# to it.
#
log4j.logger.demo.log4j.servlet.GetCommentsServlet=debug, R1

#
# For this appender and logger we are only interested in the messages from
this
# logger. We dont want the messages to print twice, first from the root
appender
# and next one from R1 appender. So we set the additivity to false.
#
log4j.additivity.demo.log4j.servlet.GetCommentsServlet=false

#
# For this we will use the RollingFileAppender and call the log file as
MDC.log
#
log4j.appender.R1=org.apache.log4j.RollingFileAppender
log4j.appender.R1.File=MDC.log

#
# This is the maximum size of this file, after which it is rolled over. The
name
# of the backup file will be MDC.log.1.. and so on. After 2 backups, the
file names
# are reused. This is set up by the MaxBackupIndex.
#
log4j.appender.R1.MaxFileSize=100KB

# Keep two backup files
log4j.appender.R1.MaxBackupIndex=2


#
# The layout is the PatternLayout
#
log4j.appender.R1.layout=org.apache.log4j.PatternLayout

#
# and the Conversion pattern includes MDC content (%X{ID})
#
log4j.appender.R1.layout.ConversionPattern=%p - [%X{RemoteHost}] - %m%n

# End of log4j.properties file




restart your server and check the server console.
you should be seeing long running logs..

let me know if u have any probe setting up this

bye
-Hari


-----Original Message-----
From: ashwani.kalra@polaris.co.in [mailto:ashwani.kalra@polaris.co.in]
Sent: Thursday, June 12, 2003 11:42 AM
To: hariharan@medicomsoft.com
Subject: RE: debugging in struts




Hi,
I  have set up the log4j (1.2.7) , But unable to get detailed out put. But
whatever is coming is logged in the tomcat log file not mine. (I am using
tomcat 4.1)

Can you tell me what configuration you had done for setting the log4j.

Regds
Ashwani



                    ashwani.kalra
                                         To:     hariharan@medicomsoft.com
                    06/11/2003           cc:
                    09:13 AM             Subject:     RE: debugging in
struts(Document link: ashwani.kalra)





Thanks,

I was not using any logging api. I will now try to configure log4j and see
the results.






                    "Hariharan"
                    <hariharan@medico        To:     "'Struts Users Mailing
List'" <st...@jakarta.apache.org>
                    msoft.com>               cc:     (bcc:
ashwani.kalra/Polaris)
                                             Subject:     RE: debugging in
struts
                    06/10/2003 01:34
                    PM
                    Please respond to
                    "Struts Users
                    Mailing List"







Hi ashwin ,

Even I was looking for somethign like this,
I wanted to check internal working of struts

I have configured log4j with a configuration file and init
servlet and I shoould tell you outcome
was very good,,

I get to see every thing srtuts does in my server console.
download log4j and configure with struts

-hari




hi,

I am not talking of any debugging tools but is there any way in which
struts api is more verbose. Like some configuration param
For eg  I was using   <html:errors /> it was not printing any errors, even
though validation framework was returning the errors. I found that the
the  value of msg attribute for validator tag was  wrong. But it was not
giving me any errors.
How to detect such errors ?

TIA
Ashwani








---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org