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 vi...@hsbc.co.in on 2006/04/10 07:31:58 UTC

Relative file path for file option!




Hi,

For a FileAppender we have the option "File".
If we provide an absolute path this works fine.
When we provide relative path, I am not able to make out with what is this
relative?
I initially assumed it to be relative the classpath, but this is not the
case.
I thought that internally it must be using File object and so the path
would be relative to the property "user.dir", but again this is not the
case.

Please help out?

Thanks and Regards,
Virender Singh,


************************************************************
HSBC Software Development (India) Pvt Ltd
HSBC Center Riverside,West Avenue ,
25 B Kalyani Nagar Pune  411 006 INDIA

Telephone: +91 20 26683000
Fax: +91 20 26681030
************************************************************


-----------------------------------------
*******************************************************************
This e-mail is confidential. It may also be legally privileged.
If you are not the addressee you may not copy, forward, disclose
or use any part of it. If you have received this message in error,
please delete it and all copies from your system and notify the
sender immediately by return e-mail.

Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability
for any errors or omissions.
*******************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Relative file path for file option!

Posted by vi...@hsbc.co.in.



Thanks for the help Arnold.
I rechecked and the relative path is being taken from the user.dir
directory as documented in java.io.File class.
Also if we use the expressions in the relative path, they are picked up
rightly.

The problem was in the way path was specified. The path started with "//"
and so the path was being taken relative to the c drive.
If this is removed then the path becomes relative and so works as
documented.



                                                                           
             Curt Arnold                                                   
             <carnold@apache.o                                             
             rg>                                                        To 
                                       Log4J Users List                    
             04/10/2006 09:50          <lo...@logging.apache.org>     
             PM                                                         cc 
             Mail Size: 5390                                               
                                                                   Subject 
             Please respond to         Re: Relative file path for file     
               "Log4J Users            option!                             
                   List"                                           Our Ref 
             <log4j-user@loggi                                             
              ng.apache.org>                                      Your Ref 
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




In a perfect world, relative paths should be resolved relative to the
configuration file.  At least that is the expected handling of
relative paths in an XML file.  However, that is not the case in
log4j.  The expected behavior is that the files are resolved relative
to the current working directory or more accurately, whatever
java.io.File does with a relative file spec.

I would suggest that you do some experimentation with adding a system
property expression to your file specification.  For example, use "$
{user.home}/myapp.log" and check that file is placed in the user's
home directory, or "${java.io.tmpdir}/myapp.log" and check that the
file is placed in the temporary file directory.  Once you have
established that, then try "${user.dir}/myapp.log".  I'd expect that
it would go exactly where "myapp.log" is currently going.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


-----------------------------------------
******************************************************************
This message originated from the Internet. Its originator may or may
not be who they claim to be and the information contained in the
message and any attachments may or may not be accurate.
******************************************************************



************************************************************
HSBC Software Development (India) Pvt Ltd
HSBC Center Riverside,West Avenue ,
25 B Kalyani Nagar Pune  411 006 INDIA

Telephone: +91 20 26683000
Fax: +91 20 26681030
************************************************************


************************************************************
HSBC Software Development (India) Pvt Ltd
HSBC Center Riverside,West Avenue ,
25 B Kalyani Nagar Pune  411 006 INDIA

Telephone: +91 20 26683000
Fax: +91 20 26681030
************************************************************


-----------------------------------------
*******************************************************************
This e-mail is confidential. It may also be legally privileged.
If you are not the addressee you may not copy, forward, disclose
or use any part of it. If you have received this message in error,
please delete it and all copies from your system and notify the
sender immediately by return e-mail.

Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability
for any errors or omissions.
*******************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Relative file path for file option!

Posted by Curt Arnold <ca...@apache.org>.
In a perfect world, relative paths should be resolved relative to the  
configuration file.  At least that is the expected handling of  
relative paths in an XML file.  However, that is not the case in  
log4j.  The expected behavior is that the files are resolved relative  
to the current working directory or more accurately, whatever  
java.io.File does with a relative file spec.

I would suggest that you do some experimentation with adding a system  
property expression to your file specification.  For example, use "$ 
{user.home}/myapp.log" and check that file is placed in the user's  
home directory, or "${java.io.tmpdir}/myapp.log" and check that the  
file is placed in the temporary file directory.  Once you have  
established that, then try "${user.dir}/myapp.log".  I'd expect that  
it would go exactly where "myapp.log" is currently going.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Relative file path for file option!

Posted by vi...@hsbc.co.in.



Hi Daniel,

I rechecked this.
I am working with WSAD java project and the "user.dir" for the same is the
path of the java project in WSAD.
If I am work using the WAS the "user.dir" is the WAS home.

But for both the case it is going relative to the c:/  drive.

Thanks and Regards,
Virender Singh,



                                                                           
             Daniel Serodio                                                
             <dserodio@pucsp.b                                             
             r>                                                         To 
             Sent by: news             log4j-user@logging.apache.org       
             <news@sea.gmane.o                                          cc 
             rg>                                                           
                                                                   Subject 
                                       Re: Relative file path for file     
             04/10/2006 08:24          option!                             
             AM                                                    Our Ref 
             Mail Size: 6473                                               
                                                                  Your Ref 
             Please respond to                                             
               "Log4J Users                                                
                   List"                                                   
             <log4j-user@loggi                                             
              ng.apache.org>                                               
                                                                           
                                                                           




virendersingh@hsbc.co.in wrote:
> Hi,
>
> I discovered that the path taken is relative to the c:/ drive on my
> machine.
>
> On looking in the code I found that a File object is being created using
> the relative pathname.
> I am a bit surprised as the javadoc of the File class says that:
>
>  * <p> A pathname, whether abstract or in string form, may be either
>  * <em>absolute</em> or <em>relative</em>.  An absolute pathname is
> complete in
>  * that no other information is required in order to locate the file that
> it
>  * denotes.  A relative pathname, in contrast, must be interpreted in
terms
> of
>  * information taken from some other pathname.  By default the classes in
> the
>  * <code>java.io</code> package always resolve relative pathnames against
> the
>  * current user directory.  This directory is named by the system
property
>  * <code>user.dir</code>, and is typically the directory in which the
Java
>  * virtual machine was invoked.
>
> So the path should have been <System.getProperty(user.dir)>/<relative
path>
> But it is not so. Please help.

Did you check the value of System.getProperty("user.dir")? I'm pretty
sure that the path _is_ relative to this property, which normally means
the directory from which the application was started.

HTH,
Daniel Serodio


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


-----------------------------------------
******************************************************************
This message originated from the Internet. Its originator may or may
not be who they claim to be and the information contained in the
message and any attachments may or may not be accurate.
******************************************************************



************************************************************
HSBC Software Development (India) Pvt Ltd
HSBC Center Riverside,West Avenue ,
25 B Kalyani Nagar Pune  411 006 INDIA

Telephone: +91 20 26683000
Fax: +91 20 26681030
************************************************************


-----------------------------------------
*******************************************************************
This e-mail is confidential. It may also be legally privileged.
If you are not the addressee you may not copy, forward, disclose
or use any part of it. If you have received this message in error,
please delete it and all copies from your system and notify the
sender immediately by return e-mail.

Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability
for any errors or omissions.
*******************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Relative file path for file option!

Posted by Daniel Serodio <ds...@pucsp.br>.
virendersingh@hsbc.co.in wrote:
> Hi,
> 
> I discovered that the path taken is relative to the c:/ drive on my
> machine.
> 
> On looking in the code I found that a File object is being created using
> the relative pathname.
> I am a bit surprised as the javadoc of the File class says that:
> 
>  * <p> A pathname, whether abstract or in string form, may be either
>  * <em>absolute</em> or <em>relative</em>.  An absolute pathname is
> complete in
>  * that no other information is required in order to locate the file that
> it
>  * denotes.  A relative pathname, in contrast, must be interpreted in terms
> of
>  * information taken from some other pathname.  By default the classes in
> the
>  * <code>java.io</code> package always resolve relative pathnames against
> the
>  * current user directory.  This directory is named by the system property
>  * <code>user.dir</code>, and is typically the directory in which the Java
>  * virtual machine was invoked.
> 
> So the path should have been <System.getProperty(user.dir)>/<relative path>
> But it is not so. Please help.

Did you check the value of System.getProperty("user.dir")? I'm pretty
sure that the path _is_ relative to this property, which normally means
the directory from which the application was started.

HTH,
Daniel Serodio


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Relative file path for file option!

Posted by vi...@hsbc.co.in.



Hi,

I discovered that the path taken is relative to the c:/ drive on my
machine.

On looking in the code I found that a File object is being created using
the relative pathname.
I am a bit surprised as the javadoc of the File class says that:

 * <p> A pathname, whether abstract or in string form, may be either
 * <em>absolute</em> or <em>relative</em>.  An absolute pathname is
complete in
 * that no other information is required in order to locate the file that
it
 * denotes.  A relative pathname, in contrast, must be interpreted in terms
of
 * information taken from some other pathname.  By default the classes in
the
 * <code>java.io</code> package always resolve relative pathnames against
the
 * current user directory.  This directory is named by the system property
 * <code>user.dir</code>, and is typically the directory in which the Java
 * virtual machine was invoked.

So the path should have been <System.getProperty(user.dir)>/<relative path>
But it is not so. Please help.

Thanks and Regards,
Virender Singh,


************************************************************
HSBC Software Development (India) Pvt Ltd
HSBC Center Riverside,West Avenue ,
25 B Kalyani Nagar Pune  411 006 INDIA

Telephone: +91 20 26683000
Fax: +91 20 26681030
************************************************************


-----------------------------------------
*******************************************************************
This e-mail is confidential. It may also be legally privileged.
If you are not the addressee you may not copy, forward, disclose
or use any part of it. If you have received this message in error,
please delete it and all copies from your system and notify the
sender immediately by return e-mail.

Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability
for any errors or omissions.
*******************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org