Solved

Unable to intialize Logger

Posted on 2006-10-27
7
447 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Read about the ways of improving workplace communication.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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