You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Ebersole, Steven" <st...@vignette.com> on 2002/07/08 15:36:04 UTC

RE: 3 basic questions

See inline...


|-----Original Message-----
|From: rayaku [mailto:yamank@nous.soft.net]
|Sent: Thursday, March 07, 2002 10:25 PM
|To: Log4J Users List
|Cc: rdoust@comcast.net
|Subject: 3 basic questions
|
|
|
|Hi,
|I found info is very clear, But I would like to know
|1. where to find the keys and how to name them ( javadoc says 
|to find in
|propertyconfigurator
|class but i could not)? Or are these predifined if yes where 
|can i find ?
|

I am assuming by "keys" you mean the values to configure.  The various
pieces of log4j follow a JavaBeans property pattern.  Log4j then uses
standard JavaBean introspection for configuring each defined piece.  In you
example of "log4j.appender.A2.file", you have previously defined (in the
config) an Appender named A2 that is some type of FileAppender.
FileAppender has a property named "file" with appropriate accessors/mutators
(i.e., getFile()/setFile()) methods.  So really you just need to look at the
options available for each individual component you are trying to configure.


|2. I am using log4j in webapplication and configured log4j 
|properties file
|   in it under web-inf\classes dir. I have a statement in 
|mylog.props file
| 	log4j.appender.A2.file=service.log
|  when i run the webapplication the service.log file is created under
|tomcat4\bin
|  directory default , Can I specify file in desired location 
|not under bin?
|

service.log is a relative path.  All OS are going to interpret that
particular relative path as ./service.log where "." represents the "current
working directory" which would be ${TOMCAT_HOME}/bin for processes running
inside the Tomcat VM.  But yes you can feed log4j an absolute path and have
it write to anywhere on the filesystem, provided the SecurityManager
currently in use allows it.  Say you want to write the log file to
${TOMCAT_HOME}/myWebApp then do the following (assuming Windows from your
use of the MS-directory seperator):
log4j.appender.A2.file=C:/tomcat4/myWebApp/service.log


|3. As log4j documents say to keep log4j.props file under 
|web-inf\classes
|directory
|   to be identified by servlet, but when the log4j.props file 
|is changed
|that changes
|will not be affected unless tomcat is restarted. Can i keep log4j.props
|under webapps/mywebapp
|directory if so how can i access it in servlet?
|

You can keep the property file somewhere else, but that in and of itself
will not solve your problem of having to restart to have changes recognized.
If it is placed somewhere other than a dir in the classpath, you will need
to tell log4j how to find it either through the log4j.configuration system
property or by programatically using the PropertyConfigurator.configure(...)
method.  In order to have changes to the prop file be automatically
recognized, you will programatically call
PropertyConfigurator.configureAndWatch(...) method.

HTH

|TIA
|</rayaku>
|
|-----Original Message-----
|From: Richard Doust [mailto:rdoust@comcast.net]
|Sent: Monday, 8 July 2002 6:41 AM
|To: Log4J Users List
|Subject: RE: options and different loggers
|
|
|I would hazard a guess that you haven't read much of the 
|material available
|on how to use log4j. Loggers inherit their behavior from a 
|runtime hierarchy
|based on their names. java.util is the parent of java.util.foo 
|and java.util
|is an ancestor of java.util.foo.bar where those dot separated names are
|names of loggers, paramters passed to Logger.getLogger(). Each 
|logger can be
|configured with different appenders and all kinds of stuff. An appender
|knows where its output goes. If your client and your service reside in
|different packages, as one would hope they might, setting them 
|up to log to
|different log files is as simple as setting them up with different
|appenders. Say you have com.rob.client.foo and com.rob.service.bar. By
|establishing loggers in your properties file for com.rob.client and
|com.rob.service, classes from those two packages down to the 
|root (i.e.,
|com.rob.service.bar.ClassA and com.rob.client.ClassB) will log 
|to different
|logfiles if you configure them with different appenders.
|In your properties file, set up as follows:
|
|log4j.logger.com.rob.service=WARN, A2
|log4j.appender.A2=org.apache.log4j.RollingFileAppender
|log4j.appender.A2.file=log/service.log
|log4j.appender.A2.layout=org.apache.log4j.PatternLayout
|log4j.appender.A2.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
|log4j.logger.com.rob.client=WARN, A3
|log4j.appender.A3=org.apache.log4j.RollingFileAppender
|log4j.appender.A3.file=log/client.log
|log4j.appender.A3.layout=org.apache.log4j.PatternLayout
|log4j.appender.A3.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
|That's about it.
|Rich
|
|-----Original Message-----
|From: Robert Mark Bram [mailto:relaxedrob@optushome.com.au]
|Sent: Sunday, July 07, 2002 6:29 AM
|To: Log4J Users List
|Subject: RE: options and different loggers
|
|
|Howdy Richard!
|
|> It means .. <snip>
|> Does that help?
|
|Yes it does, thank you - may I press you for some further help with my
|second question?
|
|>
|> I am constructing a Jini application - I will have a client and
|> service that
|> will (in the completed application) reside on different 
|machines. For now,
|> however, they will both run on the same machine, but from 
|within different
|> JVM's (communicating via RMI).
|>
|> How can I make them create different log files?
|>
|> Should I create different log4j.properties files?
|>
|> These are the primary configurations I have set in my 
|properties file:
|>
|> # I don't know what this one means
|> log4j.rootLogger=DEBUG, A1
|>
|> # Sets the primary handler to be one that writes to a file
|> log4j.appender.A1=org.apache.log4j.FileAppender
|>
|> # Sets the primary handler to be one that writes html output
|> log4j.appender.A1.layout=org.apache.log4j.HTMLLayout
|>
|
|
|Thanks!
|
|Rob
|
|:)
|:-}
|;->
|
|
|--
|To unsubscribe, e-mail:   
|<ma...@jakarta.apache.org>
|For 
|additional commands, e-mail: 
|<ma...@jakarta.apache.org>
|
|
|--
|To 
|unsubscribe, e-mail:   
|<ma...@jakarta.apache.org>
|For 
|additional commands, e-mail: 
|<ma...@jakarta.apache.org>
|
|
|--
|To 
|unsubscribe, e-mail:   
|<ma...@jakarta.apache.org>
|For 
|additional commands, e-mail: 
|<ma...@jakarta.apache.org>
|

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>