Discussion:
How to give relative log file path -RollingFileAppender
balaji ganesan
2003-01-16 18:43:02 UTC
Permalink
Hi All,
I'm using log4j-1.2.7 in my appln, deployed as a web appln in an
application server. The following is the log4j.properties file i'm using.

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=2
log4j.appender.R.File=test.log

1. How do i specify a relative path to this file name, so that it can be
created under j2ee/home/log/test.log. This j2ee/home may be under some
other top level dir ?
2. If i just specify any relative path in the property file, its not
creating the log ?

Thanks,
G.Balaji
Thomas Muller
2003-01-16 18:47:10 UTC
Permalink
| 1. How do i specify a relative path to this file name, so that it can be
| created under j2ee/home/log/test.log. This j2ee/home may be under some
| other top level dir ?

Before log4j is configured, insert the application server home path in the
System properties, e.g.

System.setProperty( "j2ee.home", <path>" )

Then insert your relative part in another property

System.setProperty( "my.log.files", <relative path>" )

Now you can use Log4j's standard variable interpolation support in your
config file:

log4j.appender.R.File=${j2ee.home}/{my.log.files}/test.log

| 2. If i just specify any relative path in the property file, its not
| creating the log ?

It will, but (probably) relative to the System variable "user.dir".

--

Thomas





*************************************************************************
Copyright ERA Technology Ltd. 2002. (www.era.co.uk). All rights reserved.
The information supplied in this Commercial Communication should be treated
in confidence.
No liability whatsoever is accepted for any loss or damage
suffered as a result of accessing this message or any attachments.

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________
balaji ganesan
2003-01-16 19:12:36 UTC
Permalink
Hi Thomas,
Thanks for your reply. My appln will be a war file deployed in the appln
server, web container.If i didn't give any directory name to log file,
as of now it creates the log file under /j2ee/home/test.log.
1. My first issue is, how does it gets this path, based on what &nbsp;system parameter
it takes up this value /j2ee/home/ and prepend it to log file ?
2. If i know the system property i need to set, i can set that to log file
location or i can append to the result of qstn 1. The idea is, if there
is a system prop that FileAppender picks it up, i can override that by a
new value as soon as the property is loaded

-Balaji
Post by Thomas Muller
| 1. How do i specify a relative path to this file name, so that it can be
| created under j2ee/home/log/test.log. This j2ee/home may be under some
| other top level dir ?
Before log4j is configured, insert the application server home path in the
System properties, e.g.
System.setProperty( "j2ee.home", <path>" )
Then insert your relative part in another property
System.setProperty( "my.log.files", <relative path>" )
Now you can use Log4j's standard variable interpolation support in your
log4j.appender.R.File=${j2ee.home}/{my.log.files}/test.log
| 2. If i just specify any relative path in the property file, its not
| creating the log ?
It will, but (probably) relative to the System variable "user.dir".
--
Thomas
*************************************************************************
Copyright ERA Technology Ltd. 2002. (www.era.co.uk). All rights reserved.
The information supplied in this Commercial Communication should be treated
in confidence.
No liability whatsoever is accepted for any loss or damage
suffered as a result of accessing this message or any attachments.
________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________
--
Thomas Muller
2003-01-16 19:30:07 UTC
Permalink
| 1. My first issue is, how does it gets this path, based on what
| &nbsp;system parameter
| it takes up this value /j2ee/home/ and prepend it to log file ?

The /j2ee/home is probably the VMs current working directory, this is why
you find your files under this directory (unless you have specified a path).
I'm sure this directory is extractable from a property. Do a printout of all
System properties after application server startup. Also consult proper
documentation. If you configure logging in a HttpServlet subclass you can do
something like this:

public void init( ServletConfig config ) throws ServletException {
super.init( config );
String baseDir = getServletContext().getRealPath( "/" );
....
}



| 2. If i know the system property i need to set, i can set that to log file
| location or i can append to the result of qstn 1. The idea is, if there
| is a system prop that FileAppender picks it up, i can override that by a
| new value as soon as the property is loaded

Not sure what you mean here.

--

Thomas





*************************************************************************
Copyright ERA Technology Ltd. 2002. (www.era.co.uk). All rights reserved.
The information supplied in this Commercial Communication should be treated
in confidence.
No liability whatsoever is accepted for any loss or damage
suffered as a result of accessing this message or any attachments.

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________
Loading...