RE: logger not working with servlet

2002-06-05 Thread Ted Velkoff

The problem is not in the property file, but rather that the servlet doesn't
know where to find the property file.

There are two parts - making sure the servlet reads the file, and second,
telling the servlet where to look.

1) This tells the configurator to read the property file when the servlet is
started

public init() {
  ...
  PropertyConfigurator.configure(filename);
  ...
}

2) But where does filename come from?  This can be a headache, but one
solution is to put it relative to some location you can easily find from
your servlet container.  In websphere, there's a system property
server.root.  Either the same exists for Tomcat or something similar.
Anyway...

public init() {
  ...
  String filename = System.getProperty(server.root) + File.separator +
log.properties
  ...  // where log.properties is the name of your log4j property file.
  ...  // of course you could have some intermediate directories under
server.root...
  PropertyConfigurator.configure(filename);
  ...
}




-Original Message-
From: Peter Choe [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 9:31 AM
To: [EMAIL PROTECTED]
Subject: logger not working with servlet


i am trying to log4j to work with a servlet on tomcat4.0 and java1.4 on a 
solaris intel machine.  but when i try to call the servlet to get it to 
log, i get the following message:

log4j:WARN No appenders could be found for logger (roster.TallyTest).
log4j:WARN Please initialize the log4j system properly.

this is my log property file:

log4j.rootLogger=debug, A1, R

log4j.appender.A1=org.apache.log4j.ConsoleAppender

log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=/export/home/tomcat/logs/coursetally.log
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
~

any suggestions on why it isn't working for my servlets, but works for 
stand alone java applications?

Peter Choe


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]



RE: logger not working with servlet

2002-06-05 Thread Shapira, Yoav

Howdy,
You're probably outputting log4j statements before the log4j system is
configured.  You need to make sure you call something like
PropertyConfigurator.configure(your config file path) before making any
log4j statements.  A good place to do this is in the init() method of a
servlet that you load on server startup.

Also, make sure that your properties file is visible to that servlet.

Yoav Shapira
Millennium ChemInformatics


-Original Message-
From: Peter Choe [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 9:31 AM
To: [EMAIL PROTECTED]
Subject: logger not working with servlet

i am trying to log4j to work with a servlet on tomcat4.0 and java1.4 on
a
solaris intel machine.  but when i try to call the servlet to get it to
log, i get the following message:

log4j:WARN No appenders could be found for logger (roster.TallyTest).
log4j:WARN Please initialize the log4j system properly.

this is my log property file:

log4j.rootLogger=debug, A1, R

log4j.appender.A1=org.apache.log4j.ConsoleAppender

log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=/export/home/tomcat/logs/coursetally.log
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
~

any suggestions on why it isn't working for my servlets, but works for
stand alone java applications?

Peter Choe


--
To unsubscribe, e-mail:   mailto:log4j-user-
[EMAIL PROTECTED]
For additional commands, e-mail: mailto:log4j-user-
[EMAIL PROTECTED]


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: logger not working with servlet

2002-06-05 Thread Peter Choe

i followed the instruction from the log4j documentation and put in my 
web.xml file the following for the servlet:


 servlet
   servlet-nameTallyTeset/servlet-name
   servlet-classroster.TallyTest/servlet-class
   init-param
  param-namelog4j-init-file/param-name
  param-valueWEB-INF/classes/roster/log4j-ct.prop/param-value
   /init-param
   load-on-startup1/load-on-startup
 /servlet

and i use the following code to read the properties file:

 public void init(ServletConfig config) throws ServletException{
 super.init(config);
 prefix = getServletContext().getRealPath(/);
 file = getInitParameter(log4j-init-file);
 System.out.println(Prefix:  + prefix);
 System.out.println(File:  + file);
 }

put looking at it the getInitParameter() method isn't reading the 
initialization from the web.xml.  is that correct?  i thought it would read 
it from the web.xml file.

At 09:48 AM 6/5/2002, Ted Velkoff wrote:
The problem is not in the property file, but rather that the servlet doesn't
know where to find the property file.

There are two parts - making sure the servlet reads the file, and second,
telling the servlet where to look.

1) This tells the configurator to read the property file when the servlet is
started

public init() {
   ...
   PropertyConfigurator.configure(filename);
   ...
}

2) But where does filename come from?  This can be a headache, but one
solution is to put it relative to some location you can easily find from
your servlet container.  In websphere, there's a system property
server.root.  Either the same exists for Tomcat or something similar.
Anyway...

public init() {
   ...
   String filename = System.getProperty(server.root) + File.separator +
log.properties
   ...  // where log.properties is the name of your log4j property file.
   ...  // of course you could have some intermediate directories under
server.root...
   PropertyConfigurator.configure(filename);
   ...
}




-Original Message-
From: Peter Choe [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 9:31 AM
To: [EMAIL PROTECTED]
Subject: logger not working with servlet


i am trying to log4j to work with a servlet on tomcat4.0 and java1.4 on a
solaris intel machine.  but when i try to call the servlet to get it to
log, i get the following message:

log4j:WARN No appenders could be found for logger (roster.TallyTest).
log4j:WARN Please initialize the log4j system properly.

this is my log property file:

log4j.rootLogger=debug, A1, R

log4j.appender.A1=org.apache.log4j.ConsoleAppender

log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=/export/home/tomcat/logs/coursetally.log
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
~

any suggestions on why it isn't working for my servlets, but works for
stand alone java applications?

Peter Choe


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]

Peter Choe


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: logger not working with servlet

2002-06-05 Thread Shapira, Yoav

Howdy,

 public void init(ServletConfig config) throws
ServletException{
 super.init(config);
 prefix = getServletContext().getRealPath(/);
 file = getInitParameter(log4j-init-file);
 System.out.println(Prefix:  + prefix);
 System.out.println(File:  + file);

1) It's a good idea to override the init() method, rather than the one
that takes a ServletConfig argument.  That way you don't have to call
super.init(config).

2) Are you deploying from a .war file?  If so, getRealPath(/) will
return null.

3) I've never had any problems getting init-params from web.xml.  I
suspect a lot of people would complain if tomcat was messing this up ;)


Are you sure the servlet whose code you posted is the one that gets
invoked?  What is the output from the two System.out.println()
statements in the code?

Yoav Shapira
Millennium ChemInformatics

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]