Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Unable to intialize Logger

Posted on 2006-10-27
7
Medium Priority
?
453 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 2000 total points
ID: 17826703
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

How to fix a SonicWall Gateway Anti-Virus firewall blocking automatic updates to apps like Windows, Adobe, Symantec, etc.
Your business may be under attack from a silent enemy that is hard to detect. It works stealthily in the shadows to access and exploit your critical business information, sensitive confidential data and intellectual property, for commercial gain. T…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

916 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