Solved

Unable to intialize Logger

Posted on 2006-10-27
7
443 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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
>>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
Comment Utility
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

11 Experts available now in Live!

Get 1:1 Help Now