Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: unable to run log code

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default unable to run log code

    while trying to run the log code it is showing org.apache.log4j.PropertyConfigurator...
    i am unable to trace out the error.
    here i am sending the code.
    package logexmaples;
     
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import java.net.URL;
     
    import org.apache.log4j.*;
    //import org.apache.log4j.properties;
    import org.apache.log4j.PropertyConfigurator.*;
     
    @SuppressWarnings("unused")
    public class SimpleLog2
    {
         private static String logFile = "/msglog.txt";
         private final static DateFormat df = new SimpleDateFormat ("yyyy.MM.dd  hh:mm:ss ");
         private SimpleLog2()
            {
     
            }
         public static void setLogFilename(String filename)
            {
                logFile = filename;
                new File(filename).delete();
                try
                  {
                       write("LOG file : " + filename);
                  }
                catch (Exception e)
                  { 
                       System.out.println(stack2string(e));
                  }
            }
         public static void write(String msg)
            {
               write(logFile, msg);
            }
        public static void write(Exception e)
            {
               write(logFile, stack2string(e));
            }
       public static void write(String file, String msg)
            {
               try
                 {
                     Date now = new Date();
                     String currentTime = SimpleLog2.df.format(now); 
                     FileWriter aWriter = new FileWriter(file, true);
                     aWriter.write(currentTime + " " + msg+ System.getProperty("line.separator"));
                     System.out.println(currentTime + " " + msg);
                     aWriter.flush();
                     aWriter.close();
                  }
                catch (Exception e)
                  {
                     System.out.println(stack2string(e));
                  }
             }
        private static String stack2string(Exception e)
             {
                try 
                  {
                     StringWriter sw = new StringWriter();
                     PrintWriter pw = new PrintWriter(sw);
                     e.printStackTrace(pw);
                     return "------\r\n" + sw.toString() + "------\r\n";
                  }
                catch(Exception e2)
                  {
                     return "bad stack2string";
                  }
              }
    }
    ---------any help
    Last edited by helloworld922; April 2nd, 2010 at 12:07 PM. Reason: Please use [code] tags!


  2. #2
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Re: unable to run log code

    can u post the exact errors and also highlight the line where error occurs

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: unable to run log code

    i am getting this error.....plz check it and reply me

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet.init() for servlet LoggerServlet threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:151)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:874)
    org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
    org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
    org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
    org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:689)
    java.lang.Thread.run(Unknown Source)


    root cause

    java.lang.NoClassDefFoundError: org/apache/log4j/PropertyConfigurator
    logexmaples.LoggerServlet.init(LoggerServlet.java: 22)
    javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:151)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:874)
    org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
    org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
    org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
    org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:689)
    java.lang.Thread.run(Unknown Source)


    root cause

    java.lang.ClassNotFoundException: org.apache.log4j.PropertyConfigurator
    org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1362)
    org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1208)
    logexmaples.LoggerServlet.init(LoggerServlet.java: 22)
    javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:151)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:874)
    org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
    org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
    org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
    org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:689)
    java.lang.Thread.run(Unknown Source)


    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Re: unable to run log code

    this is because your log4j jar is not available on the class path. Please ensure its in your tomcats lib folder

  5. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: unable to run log code

    thank u kumar...its wrkng fine....
    can u help in another doubt...

  6. #6
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Re: unable to run log code

    yeah go ahead and ask the question mate

    vinod

  7. #7
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: unable to run log code

    i am not aware of logs....but i was kept into new project which should contain logs.
    i'll describe about my project which is done on jsp,servlets,core java,html....
    its a web application contains 2 modules...
    1) Admin ---- can login and view what are the modifications done by the user i.e login,registration,update and
    logout timinings
    2) User ----- can login and do registration and can do dml,ddl operations.

    my query is log file should be created and it should contain whatever user do i.e login,logout,ddl and dml
    operations .

    i tried some examples regarding logs and log4j....but i am unable to get the answer for my project i.e where to write log file and how to call that log file in coding part i.e in servlet code...

    can u help me out... reg. this i tried so much .......

  8. #8
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Re: unable to run log code

    hi

    have attached two files which shows how to use it

    logUnit.java - this class is the master class that needs to be called in all your programs
    to use the logger

    it has two methods info and err which is used to sysout messages/ errors respectively


    admin.java - shows you how to call the logUnit class

    this should hopefully help


    thanks
    vinod
    Attached Files Attached Files

  9. The Following User Says Thank You to vkumar23 For This Useful Post:

    Json (April 6th, 2010)

  10. #9
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: unable to run log code

    thanx i'll try it...thanx a lot...bye

  11. #10
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: unable to run log code

    hi,
    gud mrng....i tried to run the program on the server but it is showing the output of another program which is previously runned...may i knw whts the prob.

  12. #11
    Junior Member
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: unable to run log code

    i m running SimpleLog2 on server it is going to other program which is lastly runned on the server....may i know why it is showing like that.

Similar Threads

  1. Unable to insert records
    By javaprogrammer11 in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: March 24th, 2010, 03:16 AM
  2. Unable to render printing the complete JPanel
    By Stephen Douglas in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 13th, 2010, 11:48 AM
  3. Unable to sendViaPost to url
    By mousumi in forum Java Networking
    Replies: 2
    Last Post: January 28th, 2010, 04:52 AM
  4. Unable to open web service tester page
    By oneofthelions in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: December 13th, 2009, 06:20 PM
  5. Unable to create a new connection!
    By fh84 in forum JDBC & Databases
    Replies: 1
    Last Post: November 20th, 2009, 05:58 PM