Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet simple web applications using log4j
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sujitha
simple web applications using log4j
2 Answer(s)      2 years and 10 months ago
Posted in : JSP-Servlet


i am getting java.lang.NoClassDefFoundError: org/apache/log4j/Logger and javax.servlet.ServletException: Error instantiating servlet class Sample exceptions when trying to execute. this is my code.............. public class Sample extends HttpServlet {

private static Logger logger= Logger.getLogger("Sample.class");   

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    PrintWriter out =response.getWriter();
    out.println(" hello sujitha");
    try
    {
        logger.info("info level");
    }
    finally
    {

    }
}

Advertisement
View Answers

February 7, 2012 at 12:51 PM


Have a look at the following link:

Log4j Tutorials



February 29, 2012 at 12:21 PM


Log4j webapplication - servlet,log4j.xml

   // Program by Nishanth Thomas ‚?? Insolutions Global Bangalore

  // example  class file   

 package com.logs;


  import java.io.IOException;
  import java.text.SimpleDateFormat;
  import java.util.Date;

  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;

  import org.apache.log4j.BasicConfigurator;
  import org.apache.log4j.FileAppender;

  import org.apache.log4j.Logger;
  import org.apache.log4j.PatternLayout;

  import org.apache.log4j.PropertyConfigurator;
  import org.apache.log4j.xml.DOMConfigurator;


public class Logscollected {


   static Logger log = Logger.getLogger(Logscollected.class);

   public static void logscollection(Exception e,       HttpServletRequest request) throws IOException{


      HttpSession session = request.getSession();

              String  exceptiondetail = ‚??‚?? ;

//create a folder in your application config and place  log4j.xml file there  and       

  // get path by the following;

      String strPath =  request.getRealPath("config");

      DOMConfigurator.configure(strPath+"/"+"log4jexp.xml");

        //create log4j.xml file as give name like  shown above log4jexp;

  try{

      ////  /* Get the Stack Trace messages //////

    e = ((e==null)?((Exception)request.getAttribute("Exception")):e);

        StackTraceElement stem[]=e.getStackTrace();

        for(int i=0;i<stem.length;i++){


      if (!exceptiondetail.equals(""))

          exceptiondetail += "\n";

          exceptiondetail += "\t";

               exceptiondetail=exceptiondetail+stem[i].toString();
        }

          log.debug(exceptiondetail);
                  //log.info(e);
                    // log.warn("Here is some WARN");
                    //  log.info(object);
          log.error(e);

          //  log.fatal("Here is some FATAL");

    }catch(Exception e1){
        e1.printStackTrace();
    }
  }

}

In the catch of any servlet call that function like this

       try{

    //     Some code‚?¶‚?¶‚?¶‚?¶

      }

    catch(Exception e)
        {

                    // Logs collection log 4j------------------------

            Logscollected.logscollection(e,request);

        //---------------------------

}

Finally log4j config file

Lo4j.xml here we renamed to log4jexp.xml to avoid conflicts with server log4j.xml file palce log4jexp.xml in config folder ( here I used)


<--configure path according to your requrmts to save log file -->

<!--code  between <log4j:configuration>  </log4j:configuration>  -->  

<appender name="daoAppender" 
   class="org.apache.log4j.RollingFileAppender">   
    <param name="maxFileSize" value="100KB" />   
    <param name="maxBackupIndex" value="2" />   
    <param name="File" value="${jboss.server.home.dir}/deploy/myexampleprj.war/serverlogs/serverlogs.txt" />   
    <layout class="org.apache.log4j.PatternLayout">   
        <param name="ConversionPattern"  
               value="%d{dd-MMM-yyyy HH:mm};%5p %c %m%n" />   
    </layout>   
</appender>   

  <--configure path according for diff packge to your requrmts to save log file -->   

<!--appender name="appAppender"  
          class="org.apache.log4j.RollingFileAppender">   
    <param name="maxFileSize" value="100KB" />   
    <param name="maxBackupIndex" value="2" />   
    <param name="File" value="${jboss.server.home.dir}/deploy/myexampleprj.war/serverlogs/serverlogs.txt" />   
    <layout class="org.apache.log4j.PatternLayout">   
        <param name="ConversionPattern"  
               value="%d{ABSOLUTE} %5p %c{1}: %m%n " />   
    </layout>    
</appender-->   

<!‚??package name given in category here com is the package give package name  -->    

<!--category name="com.ex.actions">     
    <priority value="DEBUG"/>     
    <appender-ref ref="appAppender"/>       
</category-->
<category name="com">     
    <priority value="DEBUG"/>     
    <appender-ref ref="daoAppender"/>       
</category>    

<root>   
    <!--     
    <appender-ref ref="appAppender" />   
    <appender-ref ref="daoAppender" />   
    -->    
</root>



Related Tutorials/Questions & Answers:
simple web applications using log4j
simple web applications using log4j  i am getting java.lang.NoClassDefFoundError: org/apache/log4j/Logger and javax.servlet.ServletException: Error instantiating servlet class Sample exceptions when trying to execute. this is my
log4j in web application
log4j in web application  Hi all, I am new to log4j. I want to use log4j in my web application. I need to write the debug,info,warn into a file... and how to get the logger object in web application. Thanks suresh
Advertisements
Simple Web Application using Servlet
Simple Web Application using Servlet       In this section, we have developed a simple web... a web page ("addUser.jsp")  to add the new user.    
Log4j
Log4j  what is the use of log4j in realtime?   Please visit the following link: Log4j Tutorials
log4j
log4j  explain about log4j with example ?   Please visit the following link: log4j Tutorials
Compression of rolled-over files using log4j
Compression of rolled-over files using log4j  How can I use log4j to rollover the log files on hourly basis and compress the rolled over files
LOG4J
LOG4J  HOW AND WHERE TO FIND org.prot.appserver.config.Configuration; PACKAGE TO IMPORTIN LOG4J PREOGRAM
Log4J Tutorials: Using Log4J in Easy Steps
Log4J Tutorials: Using Log4J in Easy Steps Log4j is a logging library for Java.... One of the major advantages of using Log4j is that it arranges the log output... Architecture A simple example of log4j Use of BasicConfigurator in Log4j logging
Log4J - Log4J
Log4J  What is the use of Log4j? where does it use? Log4j is using for debuging ur code. Its does the same thing as System.out/System.err do. i.e to trace out ur program   Log4j is using for debuging ur code.Its does
developing simple web service
: The Web Services Invocation Framework (WSIF) is a simple Java API...Open Source web services tool in java   .../ About Axis: Apache Axis is an implementation of the Simple Object
Top 10 Web Applications
to take advantage of developing new applications using its API, etc. On web you...When new and newer range of web based applications are virtually changing our... to choose a list of top 10 web applications. The choice is huge and similar
log4j - Log4J
log4j  could u pls help me out regarding the log4j coding   http://www.javaworld.com/javaworld/jw-12-2004/jw-1220-toolbox.html Thanks
Java Building a Simple Web Service ? A Tutorial Tutorial
in designing and developing enterprise class web applications using JAVA and J2EE... Building a Simple Web Service ? A Tutorial... In this tutorial we will create a simple web service and a client web application
how to design control panel for web applications
how to design control panel for web applications  how to design control panel for web applications
Internationalization and Localization of Web Applications in Java
Internationalization and Localization of Web Applications in Java... applications in java. Localization of Web applications means that a web.... Internationalization of Web applications means that a web application that is created
log4j - Log4J
log4j  give me explanation about log4j,junit? how i hvae to use them   Hi mamatha, In Log4J, if you log a message at DEBUG level, and the current Appender is set to only log messages of INFO level and above
how to communicate with different web applications - JSP-Servlet
how to communicate with different web applications  how to communicate with different web applications which are under same or different servers? ex... to second/jsp/show.jsp without using query string like that can u guide me how
Simple application using hibernate
Simple application using hibernate  Hi, How to write a simple application using hibernate in Eclipse IDE? I would like to to learn: Process... of the tutorial you will like to learn for creating the simple application using
JBoss Seam - Web 2.0 Applications
web applications with simple annotated Plain Old Java Objects (POJOs...JBoss Seam - Web 2.0 Applications      ... generation Web 2.0 applications. It unifies and integrates technologies
How to communicate with different web applications ? ? ? ? - JSP-Servlet
How to communicate with different web applications ? ? ? ?  Deepak ji... with different web applications which are under same or different servers? ex.../show.jsp without using query string like that In your answer display.jsp
*** How to communicate with different web applications ? ? ? ? - JSP-Servlet
*** How to communicate with different web applications ? ? ? ?  ... to communicate with different web applications which are under same or different servers? ex.../show.jsp without using query string like that In your answer display.jsp
How to communicate with different web applications ? ? ? ? - JSP-Servlet
How to communicate with different web applications ? ? ? ?  How to communicate with different web applications which are under same or different... to second/jsp/show.jsp without using query string like that can u guide me how
* How to communicate with different web applications ? ? ? ? - JSP-Servlet
* How to communicate with different web applications ? ? ? ?  Deepak... with different web applications which are under same or different servers? ex.../show.jsp without using query string like that In your answer display.jsp
How Traditional Web Applications Works
How Traditional Web Applications Works         How traditional web... web applications and then in the next section we will explore the working
Characteristics of simple Web 2.0 Website
Characteristics of simple Web 2.0 Website       Before making any Web 2.0 site, the programmers must... is the fundamental thing. The web designers should have to design a very simple, sober
Regarding Simple Web service example - WebSevices
Regarding Simple Web service example  hi i am trying to follow the simple web service example in the tutorials and it develops the application in Netbeans IDE using the GlassFish Server . however when i did the same
Hibernate Logging using Log4j
This section contains detail description of how you can use Log4j for logging configuration
Web 2.0 Characteristics,Web 2.0 Applications,Web 2.0 Conference,Web 2.0 Tools,Web 2.0 Technologies,Web 2.0 Techniques
using Web 2.0 is different. Some uses it accidentally as for browsing purpose. Some... Web 2.0 Characteristics       Characteristics of Web 2.0 Though there is a controversy still going
Simple banking system using Java
Simple banking system using Java  I am trying to make a simple... and the other is the branch, the third interface is the main class. Using inheritance the branch is supposed to inherit the activities of the main office...using
Use of BasicConfigurator in Log4j logging
In this part of tutorial we will tell you how to configure log4j using... Use of BasicConfigurator in Log4j logging       log4j warning log4j: WARN No appenders could
Simple HTML example
Simple HTML example In this section we will give you very simple example of a HTML page. After reading this page you should be able to create simple HTML pages for your website. HTML is used to create web pages for websites. You
 

 

 

DMCA.com