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 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
    {

    }
}
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
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
Simple Web Application using Servlet
Simple Web Application using Servlet       In this section, we have developed a simple web...; Step:2 Create a web page ("addUser.jsp")  to add the new user
log4j
log4j  explain about log4j with example ?   Please visit the following link: log4j Tutorials
Log4j
Log4j  what is the use of log4j in realtime?   Please visit the following link: Log4j Tutorials
Log4J Tutorials: Using Log4J in Easy Steps
Log4J Tutorials: Using Log4J in Easy Steps Log4j is a logging library for Java... file.ADS_TO_REPLACE_1 One of the major advantages of using Log4j is that it arranges... at Rose India Log4J Architecture A simple example of log4j Use
LOG4J
LOG4J  HOW AND WHERE TO FIND org.prot.appserver.config.Configuration; PACKAGE TO IMPORTIN LOG4J PREOGRAM
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
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
Top 10 Web Applications
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... afar. In selecting our preferred web applications we would like to represent
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
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
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
* 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 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 ? ? ? ?  ... 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 ? ? ? ?  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
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
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
Hibernate Logging using Log4j
This section contains detail description of how you can use Log4j for logging configuration
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 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
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...; Introduction In this tutorial we will create a simple web service and a client web
Version of log4j>log4j dependency
List of Version of log4j>log4j dependency
Building Search Engine Applications Using Servlets !
Building Search Engine Applications Using Servlets Introduction...   2. Java programmers writing web applications. What you should know... using Java Servlets. You can Download the source code of search
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
Maven dependency for log4j - log4j version 1.2.15 is released. Learn to use log4j version 1.2.15 in Maven based Java projects
Maven dependency for  log4j  - Version 1.2.15 of log4j released The developers of   log4j - log4j project have released the latest version of this library on 30 Aug 2007, the released version of  log4j - log4j
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
Log4j 2.15.0 maven dependency - Fixing log4j zero day vulnerability
vulnerability. So, if you are using old affected version of Log4j library... is found in very popular Apache log4j 2 library being used by applications... in their application. What is Log4j 2.15.0 maven dependency for using in the Java
Characteristics of simple Web 2.0 Website
Characteristics of simple Web 2.0 Website       Before making any Web 2.0 site, the programmers must keep in mind the following things, which suits the Web 2.0 technology
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
Maven Repository/Dependency: log4j | log4j
Maven Repository/Dependency of Group ID log4j and Artifact ID log4j. Latest version of log4j:log4j dependencies. # Version...? How to create Maven Web Application in Eclipse? Maven 3 Tutorial
java - Log4J
, an OutputStream, a java.io.Writer etc. Using Log4j it is possible to enable logging... regarding "LOG4J" and where these are exactly used in realtime application and purpose of using this,thanks in advance,i hope i may get reply for this as soon
Log4J Architecture - Introduction to the Log4J architecture
. Configuring Log4J For running application using Log4J you need..._TO_REPLACE_6 There are two ways to configure the Log4J one is by using properties file and other by using xml file. Using xml for Log4J is quite popular
log4j - Java Interview Questions
log4j  plz send me example program, using log4j and tel me how to execute that program.(what are the requirements to execute that program
Configuring Log4J
Configuring Log4J  Is it possible to configure xml file in such a way that it has different logging levels for diferent packages in java through Log4J
Log4j error - Log4J
Log4j error  Error while running tomcat server. SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener java.lang.NoClassDefFoundError: org
Hibernate Simple Program Using Java Application with Eclipse
Hibernate Simple Program Using Java Application with Eclipse  How to write Hibernate Simple Program Using Java Application with Eclipse? I wish to learn Hibernate using very popular Eclipse IDE. Share me the best tutorial link
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
hi - Log4J
hi  Please give me the clear definition of Log4J and give me the example
Difficulty in plugging log4J with Hibernate.
Difficulty in plugging log4J with Hibernate.  I am using Hibernate 3.6. Followed your all instruction of plugging log4j with my hibernate code... HandlingWorker, it uses SLF4j and does not detect log4J. What could
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
ModuleNotFoundError: No module named 'simple-web-discover'
ModuleNotFoundError: No module named 'simple-web-discover'  Hi, My... named 'simple-web-discover' How to remove the ModuleNotFoundError: No module named 'simple-web-discover' error? Thanks   Hi
Help in Semantic web using SweDe
Help in Semantic web using SweDe  Hey I am very new to we programming and wondering if I can find the tutorial for learning Semantic development using SweDe
java - Log4J
java  Q What is the real use for log4J?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorials/log4j/index.shtml Thanks
Why Web Services?
using ftp protocol (Web services over FTP). Loosely Coupled Applications: Web... will understand why Web Services are developed and what are the benefits of using Web Services for  the development of  Enterprise applications. Why

Ads