Solved

Unable to intialize Logger

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
timeToIdleSeconds vs timeToLiveSeconds in hibernate second level cache 3 138
spring example non maven 4 92
how to hide hide popup page refresh second time? 10 139
ejb on wildfly 5 30
The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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