Solved

Unable to intialize Logger

Posted on 2006-10-27
7
444 Views
Last Modified: 2010-05-18
Hi Experts,

I have one application in which I am trying to facilitate it thru logger..
but now application has started throwing runtime excpetion...

--------------------------------------------------------------------------
type Exception report

message

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

exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.ExceptionInInitializerError
      sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      java.lang.reflect.Constructor.newInstance(Constructor.java:494)
      java.lang.Class.newInstance0(Class.java:350)
      java.lang.Class.newInstance(Class.java:303)
      org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:143)
      org.apache.struts.action.RequestProcessor.processActionCreate(RequestProcessor.java:280)
      org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:218)
      org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
      org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

------------------------------------------------------------------------------------
I have initialized in my action class(LoginAction)

package com.yourcompany.struts;

import java.util.ArrayList;

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

import org.apache.struts.action.*;
import org.apache.log4j.Logger;

public class LoginAction extends Action{
      
      public static int i;
      private static final Logger logger= Logger.getLogger(ActionForm.class);
      
      public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws java.lang.Exception
      {
          logger.debug("->> Execute");
            LoginForm frm= (LoginForm)form;
            NameclassService ncs;
            
            ArrayList name_list=frm.getTotal_name();
            
            ncs= new NameclassService();
                  
            
            ncs.setLoginForm(frm);
            name_list=(ArrayList)ncs.fetchName();
            
            frm.setTotal_name(name_list);
            return mapping.findForward("success");
            
      }

}

----------------------------------------------------------------
also I am getting warnings while starting server..................
log4j:WARN No appenders could be found for logger (org.apache.catalina.session.ManagerBase).
log4j:WARN Please initialize the log4j system properly.

Pls Help...

Dojjol
0
Comment
Question by:dojjol
  • 3
7 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 17825750
I think that you have to set the log4j.properties somewhere.

http://forum.java.sun.com/thread.jspa?threadID=404853&start=0
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17826037
use this code from my project


If you want to create log files using log4j, there is a certain programming structure you have to follow like this


+++++++++++++++++
import java.io.File;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.Priority;
import org.apache.log4j.RollingFileAppender;

private Logger standardLogger;
String loggerName = "MyProjectLogger";
File standardlogPath = new File(standardLogFilePath);
//standardLogFilePath  is directory where you want the log files to be stored. so   standardLogFilePath=c:/logfiles
if (!standardlogPath.exists()) {
standardlogPath.mkdirs();   //if directory doesnt exist , create one
}

PatternLayout layout =
new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN);
layout = new PatternLayout("%d - %p - %m%n");
//PatternLayout  is a predefined class provided by log4j

RollingFileAppender fileAppender1 = new RollingFileAppender();
//RollingFileAppender is a predefined class provided by log4j package
fileAppender1 = new RollingFileAppender(layout, standardLogFilePath + standardLogFileName,
true);


//standardLogLevel is the log level which you have to set based on your project requirments.It can be debug,info,warn,error or fatal
//check for standardLogLevel conditions and set threshhold(Priority ) accordingly

if (standardLogLevel.equals("DEBUG")) {
fileAppender1.setThreshold(Priority.DEBUG);
} else if (standardLogLevel.equals("INFO")) {
fileAppender1.setThreshold(Priority.INFO);
} else if (standardLogLevel.equals("WARN")) {
fileAppender1.setThreshold(Priority.WARN);
} else if (standardLogLevel.equals("ERROR")) {
fileAppender1.setThreshold(Priority.ERROR);
} else if (standardLogLevel.equals("FATAL")) {
fileAppender1.setThreshold(Priority.FATAL);
}

standardLogger = Logger.getLogger(loggerName);
standardLogger.addAppender(fileAppender1);
//you have to use above line, that is why you are getting error No appenders found!
            }
0
 

Author Comment

by:dojjol
ID: 17826597
>>I think that you have to set the log4j.properties somewhere.
I have already set Log4J.properties under WEB-INF/classes folder as I am using Tomcat...
It is not helping..

I want to use Log4J utility thru properties file...
Is it really neccsary to write a class for intializing logger....as tomcat automatically intiliazes Log4J.properties when kept under WEB-INF/classes folder

Pls suggest

Regards,
dojjol
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17826693
>>Is it really neccsary to write a class for intializing logger

you dont have to.

Just make sure you have everything setup properly in the log4j.properties file. make sure you have these in it

log4j.rootLogger=info, A
log4j.appender.A=org.apache.log4j.ConsoleAppender
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n


 
0
 
LVL 10

Accepted Solution

by:
jaggernat earned 500 total points
ID: 17826703
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now