User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,509 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,661 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1293 | Replies: 3
Reply
Join Date: Feb 2007
Posts: 18
Reputation: aruna_k_2006 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
aruna_k_2006's Avatar
aruna_k_2006 aruna_k_2006 is offline Offline
Newbie Poster

log4j problem

  #1  
Sep 24th, 2007
hi ,i want to print e.printStackTrace in File using log 4j but its giving error ........
these r my files

web1.xml
<context-param>
<param-name>driverName</param-name>
<param-value>com.microsoft.jdbc.sqlserver.SQLServerDriver</param-value>
</context-param>
<context-param>
<param-name>log4j1</param-name>
<param-value>WEB-INF/classes/log4j.properties</param-value>

</context-param>


MyListener.java


publicclass MyListener implements ServletContextListener{
Connection con;
public void contextInitialized(ServletContextEvent sce)
{
try{
ServletContext sctx=sce.getServletContext();
String log1=sctx.getInitParameter("log4j1");
sctx.setAttribute("log1",log1);
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public void contextDestroyed(ServletContextEvent sce1)
{
try
{
ServletContext ctx1=sce1.getServletContext();
con=(Connection)ctx1.getAttribute("Connection");
con.close();
}
catch(Exception e1)
{
e1.printStackTrace();
}
}

}



Servlet:
-------------
----------------


----------------------





package Student;
import java.text.SimpleDateFormat;
import java.util.*;

import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.lang.Object;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
publicclass AddTimeTableBean extends Object {
Connection con;
ResultSet rs;
Statement st;
String b;
boolean flag;
private String UserID;
private static Logger logger;
public AddTimeTableBean()
{}

public AddTimeTableBean(Connection con)
{
PropertyConfigurator.configure("log4j.properties");
logger= Logger.getLogger(GetHeaderBean.class.getName());

try
{
this.con = con;
st=con.createStatement();
}
catch (Exception e)
{
e.printStackTrace();
}
}

public void doProcess()
{
try
{
//select stmts

}
catch(Exception e)
{
e.printStackTrace();
logger.error("e",e.printStackTrace();//main error

}

log4j.properties


log4j.rootLogger=ERROR,stdout,R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=crmngt.log
log4j.appender.R.MaxFileSize=1000KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
Nikki
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,090
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 307
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: log4j problem

  #2  
Sep 24th, 2007
You did not post what error you are receiving.
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: log4j problem

  #3  
Sep 24th, 2007
just a quick scan revealed at least one syntax error in the Java code.
Didn't bother to try to make sense of the rest after that, if you can't get it to compile there's little sense going further.

Anyway, it's a bad idea to have your web app keep its own log4j config (and I suppose jar file). Have the appserver handle logging for you.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Apr 2006
Location: City of God
Posts: 163
Reputation: orko is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: log4j problem

  #4  
Sep 24th, 2007
I am also working on similar project.

Note the following documentation:
public void error(java.lang.Object message, java.lang.Throwable t) 
But you are passing a null object instead of throwable.
logger.error("e",e.printStackTrace();//main error
You may simplify this by:
logger.error(e.getMessage());
Let me know if it works for you. It will also help me in my project.
Thanks.
A Perfect World
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 3:47 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC