RE: Location of log files

2003-08-27 Thread Shapira, Yoav

Howdy,
Cool, thanks for posting your final solution! ;)

Yoav Shapira
Millennium ChemInformatics


>-Original Message-
>From: Larry Young [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, August 27, 2003 3:56 PM
>To: Log4J Users List
>Subject: RE: Location of log files
>
>Yaov,
>
> Agg  why didn't I check the book before posting
>that!!   On page 101 of Ceki's book, the File option has a full
description
>associated with it, including the note about having to escape the '\'
on
>the windoze platform, and also about being able to simply use the '/'
>instead.  Having said that, it might be useful to have that note in the
>javadocs too. :)
>
> So basically all I need to do is simply convert my
CATALINA_HOME
>value to use '/'.  Sorry for wasting everyone's time.
>
> BTW, I did look at the fixCRLF task, but that operates on the
>entire file, and I wasn't sure that there wouldn't be any '\'
characters
>somewhere else in my log4j.xml file.  So, the final solution that I
came up
>with is as follows, and this should work on both Windoze & *nix.
>
> value="${env.CATALINA_HOME}/webapps/MYAPP"/>
>
>  
>
>
>  path=${installdir}/WEB-INF/${ant.project.name}.log/>
>
>   file="${basedir}/config/log4j.xml"
>  filtering="true"/>
>
>  
>
> Thanks again for all your help!
>
>--- regards ---
>Larry
>
>At 01:54 PM 8/27/03 -0400, you wrote:
>
>>Howdy,
>>Ant can handle either way, forward or back, as long as it's
consistent.
>>The problem arises when a single string uses mixed slashes.  Ant's
>>FixCRLF task works in this area and might be useful here.
>>
>>Yoav Shapira
>>Millennium ChemInformatics
>>
>>
>> >-Original Message-
>> >From: Larry Young [mailto:[EMAIL PROTECTED]
>> >Sent: Wednesday, August 27, 2003 1:57 PM
>> >To: Log4J Users List
>> >Subject: RE: Location of log files
>> >
>> >Yoav,
>> >
>> > Thanks for the suggestion, but that doesn't work either.
>> >
>> > So now I have:
>> >  > >value="${env.CATALINA_HOME}/webapps/MYAPP"/>
>> >
>> >  
>> >> >value="${installdir>/WEB_INF/>
>> >> >   file="${basedir}/config/log4j.xml"
>> >  filtering="true"/>
>> >  
>> >
>> > And the generated log4j.xml file has the same mixed / & \
>>values.
>> >
>> > Beyond that, I tried to manually change all the '/' to '\'
in
>>the
>> >generated log4j.xml file and when I ran it, it put the file under
>> >tomcat/bin and its name was the concatenation of all the path
elements.
>>I
>> >then tried to "escape" the backslash and that worked fine!  This
would
>> >sound like a problem with the xml parser log4j is using when it is
>>parsing
>> >the "value" param and handing it to log4j.
>> >
>> > Oddly enough, when I changed all the backslash's to
>> >forward-slash's, that worked too.  I thought on a Windoze box, Java
>>used
>> >the system-dependent filenaming conventions when creating a
>> >FileOutputStream (which is all that log4j does with the filename)?
>> >
>> > So are you doing this currently on a windoze or *nix box?
I
>>can
>> >see how it would work in a non-M$ environment.  Thoughts?
>> >
>> >--- regards ---
>> >Larry
>> >
>> >
>> >At 12:39 PM 8/27/03 -0400, you wrote:
>> >
>> >>Howsdy,
>> >>Try
>> >>
>> >>outside a filterset. (i.e. no filterset at all, just the above line
>> >>above the  task.
>> >>
>> >>Yoav Shapira
>> >>Millennium ChemInformatics
>> >>
>> >>
>> >> >-Original Message-
>> >> >From: Larry Young [mailto:[EMAIL PROTECTED]
>> >> >Sent: Wednesday, August 27, 2003 11:36 AM
>> >> >To: Log4J Users List
>> >> >Subject: RE: Location of log files
>> >> >
>&

RE: Location of log files

2003-08-27 Thread Larry Young
Yaov,

Agg  why didn't I check the book before posting 
that!!   On page 101 of Ceki's book, the File option has a full description 
associated with it, including the note about having to escape the '\' on 
the windoze platform, and also about being able to simply use the '/' 
instead.  Having said that, it might be useful to have that note in the 
javadocs too. :)

So basically all I need to do is simply convert my CATALINA_HOME 
value to use '/'.  Sorry for wasting everyone's time.

BTW, I did look at the fixCRLF task, but that operates on the 
entire file, and I wasn't sure that there wouldn't be any '\' characters 
somewhere else in my log4j.xml file.  So, the final solution that I came up 
with is as follows, and this should work on both Windoze & *nix.



 
   
   
 
   
   
  file="${basedir}/config/log4j.xml"
 filtering="true"/>
   
 

Thanks again for all your help!

--- regards ---
Larry
At 01:54 PM 8/27/03 -0400, you wrote:

Howdy,
Ant can handle either way, forward or back, as long as it's consistent.
The problem arises when a single string uses mixed slashes.  Ant's
FixCRLF task works in this area and might be useful here.
Yoav Shapira
Millennium ChemInformatics
>-Original Message-
>From: Larry Young [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, August 27, 2003 1:57 PM
>To: Log4J Users List
>Subject: RE: Location of log files
>
>Yoav,
>
> Thanks for the suggestion, but that doesn't work either.
>
> So now I have:
>  value="${env.CATALINA_HOME}/webapps/MYAPP"/>
>
>  
>value="${installdir>/WEB_INF/>
>   file="${basedir}/config/log4j.xml"
>  filtering="true"/>
>  
>
> And the generated log4j.xml file has the same mixed / & \
values.
>
> Beyond that, I tried to manually change all the '/' to '\' in
the
>generated log4j.xml file and when I ran it, it put the file under
>tomcat/bin and its name was the concatenation of all the path elements.
I
>then tried to "escape" the backslash and that worked fine!  This would
>sound like a problem with the xml parser log4j is using when it is
parsing
>the "value" param and handing it to log4j.
>
> Oddly enough, when I changed all the backslash's to
>forward-slash's, that worked too.  I thought on a Windoze box, Java
used
>the system-dependent filenaming conventions when creating a
>FileOutputStream (which is all that log4j does with the filename)?
>
> So are you doing this currently on a windoze or *nix box?  I
can
>see how it would work in a non-M$ environment.  Thoughts?
>
>--- regards ---
>Larry
>
>
>At 12:39 PM 8/27/03 -0400, you wrote:
>
>>Howsdy,
>>Try
>>
>>outside a filterset. (i.e. no filterset at all, just the above line
>>above the  task.
>>
>>Yoav Shapira
>>Millennium ChemInformatics
>>
>>
>> >-Original Message-
>> >From: Larry Young [mailto:[EMAIL PROTECTED]
>> >Sent: Wednesday, August 27, 2003 11:36 AM
>> >To: Log4J Users List
>> >Subject: RE: Location of log files
>> >
>> >Hello,
>> >
>> > This is a question about a post from several weeks ago.  I
>>wasn't
>> >ready to try it at the time, but I saved it because I knew I'd need
it
>> >later on ... :)
>> >
>> > When I tried to use "filtering" as described in the
original
>>post
>> >(actually, I created a "filterset" inside the copy tag), it works
fine
>> >except that on Windows 2K it contains back-slashes(\) from my
>> >$CATALINA_HOME env variable and forward-slashes(/) from the subpath
>>info
>> >inside of Ant.  Then, when log4j gets it, the backslashes are
>>effectively
>> >ignored (probably interpreted as "escaping" the next character) so
>>log4j
>> >complains that no such directory exists.
>> >
>> > Is there a way to get log4j to accept either path-separator
>> >character, or alternately is anyone aware of an Ant function to
force
>> >"filtering" to use the platform-dependent path separator when
replacing
>> >text ??
>> >
>> >My Ant build.xml looks ba

RE: Location of log files

2003-08-27 Thread Shapira, Yoav

Howdy,
Ant can handle either way, forward or back, as long as it's consistent.
The problem arises when a single string uses mixed slashes.  Ant's
FixCRLF task works in this area and might be useful here.

Yoav Shapira
Millennium ChemInformatics


>-Original Message-
>From: Larry Young [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, August 27, 2003 1:57 PM
>To: Log4J Users List
>Subject: RE: Location of log files
>
>Yoav,
>
> Thanks for the suggestion, but that doesn't work either.
>
> So now I have:
>  value="${env.CATALINA_HOME}/webapps/MYAPP"/>
>
>  
>value="${installdir>/WEB_INF/>
>   file="${basedir}/config/log4j.xml"
>  filtering="true"/>
>  
>
> And the generated log4j.xml file has the same mixed / & \
values.
>
> Beyond that, I tried to manually change all the '/' to '\' in
the
>generated log4j.xml file and when I ran it, it put the file under
>tomcat/bin and its name was the concatenation of all the path elements.
I
>then tried to "escape" the backslash and that worked fine!  This would
>sound like a problem with the xml parser log4j is using when it is
parsing
>the "value" param and handing it to log4j.
>
> Oddly enough, when I changed all the backslash's to
>forward-slash's, that worked too.  I thought on a Windoze box, Java
used
>the system-dependent filenaming conventions when creating a
>FileOutputStream (which is all that log4j does with the filename)?
>
> So are you doing this currently on a windoze or *nix box?  I
can
>see how it would work in a non-M$ environment.  Thoughts?
>
>--- regards ---
>Larry
>
>
>At 12:39 PM 8/27/03 -0400, you wrote:
>
>>Howsdy,
>>Try
>>
>>outside a filterset. (i.e. no filterset at all, just the above line
>>above the  task.
>>
>>Yoav Shapira
>>Millennium ChemInformatics
>>
>>
>> >-Original Message-
>> >From: Larry Young [mailto:[EMAIL PROTECTED]
>> >Sent: Wednesday, August 27, 2003 11:36 AM
>> >To: Log4J Users List
>> >Subject: RE: Location of log files
>> >
>> >Hello,
>> >
>> > This is a question about a post from several weeks ago.  I
>>wasn't
>> >ready to try it at the time, but I saved it because I knew I'd need
it
>> >later on ... :)
>> >
>> > When I tried to use "filtering" as described in the
original
>>post
>> >(actually, I created a "filterset" inside the copy tag), it works
fine
>> >except that on Windows 2K it contains back-slashes(\) from my
>> >$CATALINA_HOME env variable and forward-slashes(/) from the subpath
>>info
>> >inside of Ant.  Then, when log4j gets it, the backslashes are
>>effectively
>> >ignored (probably interpreted as "escaping" the next character) so
>>log4j
>> >complains that no such directory exists.
>> >
>> > Is there a way to get log4j to accept either path-separator
>> >character, or alternately is anyone aware of an Ant function to
force
>> >"filtering" to use the platform-dependent path separator when
replacing
>> >text ??
>> >
>> >My Ant build.xml looks basically like this:
>> >
>> > > >value="${env.CATALINA_HOME}/webapps/MYAPP"/>
>> >
>> > 
>> >   > >  file="${basedir}/config/log4j.xml">
>> > 
>> >   > > class="... RollingFileApppender">
>> >   > >param is "C:\Java\tomcat/webapps/MYAPP/WEB_INF/myapp.log".  Any
>>thoughts
>> >???
>> >
>> >--- regards ---
>> >Larry
>> >
>> >
>
>--
>Larry Young
>The Dalmatian Group
>www.dalmatian.com
>
>
>
>-
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]




This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


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



RE: Location of log files

2003-08-27 Thread Larry Young
Yoav,

Thanks for the suggestion, but that doesn't work either.

So now I have:
 

 
   
 
And the generated log4j.xml file has the same mixed / & \ values.

Beyond that, I tried to manually change all the '/' to '\' in the 
generated log4j.xml file and when I ran it, it put the file under 
tomcat/bin and its name was the concatenation of all the path elements.  I 
then tried to "escape" the backslash and that worked fine!  This would 
sound like a problem with the xml parser log4j is using when it is parsing 
the "value" param and handing it to log4j.

Oddly enough, when I changed all the backslash's to 
forward-slash's, that worked too.  I thought on a Windoze box, Java used 
the system-dependent filenaming conventions when creating a 
FileOutputStream (which is all that log4j does with the filename)?

So are you doing this currently on a windoze or *nix box?  I can 
see how it would work in a non-M$ environment.  Thoughts?

--- regards ---
Larry
At 12:39 PM 8/27/03 -0400, you wrote:

Howsdy,
Try

outside a filterset. (i.e. no filterset at all, just the above line
above the  task.
Yoav Shapira
Millennium ChemInformatics
>-Original Message-
>From: Larry Young [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, August 27, 2003 11:36 AM
>To: Log4J Users List
>Subject: RE: Location of log files
>
>Hello,
>
> This is a question about a post from several weeks ago.  I
wasn't
>ready to try it at the time, but I saved it because I knew I'd need it
>later on ... :)
>
> When I tried to use "filtering" as described in the original
post
>(actually, I created a "filterset" inside the copy tag), it works fine
>except that on Windows 2K it contains back-slashes(\) from my
>$CATALINA_HOME env variable and forward-slashes(/) from the subpath
info
>inside of Ant.  Then, when log4j gets it, the backslashes are
effectively
>ignored (probably interpreted as "escaping" the next character) so
log4j
>complains that no such directory exists.
>
> Is there a way to get log4j to accept either path-separator
>character, or alternately is anyone aware of an Ant function to force
>"filtering" to use the platform-dependent path separator when replacing
>text ??
>
>My Ant build.xml looks basically like this:
>
> value="${env.CATALINA_HOME}/webapps/MYAPP"/>
>
> 
> file="${basedir}/config/log4j.xml">
> 
>class="... RollingFileApppender">
>   param is "C:\Java\tomcat/webapps/MYAPP/WEB_INF/myapp.log".  Any
thoughts
>???
>
>--- regards ---
>Larry
>
>
--
Larry Young
The Dalmatian Group
www.dalmatian.com 



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


RE: Location of log files

2003-08-27 Thread Shapira, Yoav

Howsdy,
Try

outside a filterset. (i.e. no filterset at all, just the above line
above the  task.

Yoav Shapira
Millennium ChemInformatics


>-Original Message-
>From: Larry Young [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, August 27, 2003 11:36 AM
>To: Log4J Users List
>Subject: RE: Location of log files
>
>Hello,
>
> This is a question about a post from several weeks ago.  I
wasn't
>ready to try it at the time, but I saved it because I knew I'd need it
>later on ... :)
>
> When I tried to use "filtering" as described in the original
post
>(actually, I created a "filterset" inside the copy tag), it works fine
>except that on Windows 2K it contains back-slashes(\) from my
>$CATALINA_HOME env variable and forward-slashes(/) from the subpath
info
>inside of Ant.  Then, when log4j gets it, the backslashes are
effectively
>ignored (probably interpreted as "escaping" the next character) so
log4j
>complains that no such directory exists.
>
> Is there a way to get log4j to accept either path-separator
>character, or alternately is anyone aware of an Ant function to force
>"filtering" to use the platform-dependent path separator when replacing
>text ??
>
>My Ant build.xml looks basically like this:
>
> value="${env.CATALINA_HOME}/webapps/MYAPP"/>
>
> 
> file="${basedir}/config/log4j.xml">
> 
>class="... RollingFileApppender">
>   param is "C:\Java\tomcat/webapps/MYAPP/WEB_INF/myapp.log".  Any
thoughts
>???
>
>--- regards ---
>Larry
>
>
>At 01:54 PM 8/5/03 -0400, Shapira, Yoav wrote:
>
>>Howdy,
>>This is a common problem, and you have several options.
>>
>> >The logging works fine. The problem is specifying the location of
the
>>log
>> >file.
>> >I use log4j.xml to configure log4j. In there I have to specify the
>>location
>> >of the
>> >log file as absolute path. This creates a problem because we have to
>>edit
>>
>>You don't have to specify the path as absolute: it can be relative (to
>>the working directory), and it can contain environment variables.
>>
>> >log4j.xml
>> >during each deployment of our application to edit the location of
the
>>log
>> >file.
>>
>>Another option is to automate this by copying the log4j.xml file with
>>filtering="true" in Ant.  In log4j.xml you'd have a token value for
the
>>log file path, e.g. @logFilePath@, and when deploying you'd have Ant
>>replace this value with a value coming from an Ant property.
>>
>> >I attempted to solve the problem by adding the following code in a
>>utility
>> >class
>> >
>> >   rootLogger = Logger.getRootLogger();
>> >   FileAppender fp = (FileAppender)
>> >rootLogger.getAppender("LOGFILE");
>>
>>This is yet another option, the pure programmatic way.  I find this
>>useful some time, but cleaner if you create the appender
>>programmatically as well, i.e.
>>Layout l = ...
>>String logFilePath = 
>>Appender app = new FileAppder(l, logFilePath);
>>Logger.getRootLogger().addAppender(app)
>>
>>Yoav Shapira
>>
>>
>>
>>This e-mail, including any attachments, is a confidential business
>>communication, and may contain information that is confidential,
>>proprietary and/or privileged.  This e-mail is intended only for the
>>individual(s) to whom it is addressed, and may not be saved, copied,
>>printed, disclosed or used by anyone else.  If you are not the(an)
>>intended recipient, please immediately delete this e-mail from your
>>computer system and notify the sender.  Thank you.
>>
>>
>>-
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>
>--
>Larry Young
>The Dalmatian Group
>www.dalmatian.com
>
>
>
>-
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]




This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


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



RE: Location of log files

2003-08-27 Thread Larry Young
Hello,

This is a question about a post from several weeks ago.  I wasn't 
ready to try it at the time, but I saved it because I knew I'd need it 
later on ... :)

When I tried to use "filtering" as described in the original post 
(actually, I created a "filterset" inside the copy tag), it works fine 
except that on Windows 2K it contains back-slashes(\) from my 
$CATALINA_HOME env variable and forward-slashes(/) from the subpath info 
inside of Ant.  Then, when log4j gets it, the backslashes are effectively 
ignored (probably interpreted as "escaping" the next character) so log4j 
complains that no such directory exists.

Is there a way to get log4j to accept either path-separator 
character, or alternately is anyone aware of an Ant function to force 
"filtering" to use the platform-dependent path separator when replacing text ??

My Ant build.xml looks basically like this:




  

  
  

--- regards ---
Larry
At 01:54 PM 8/5/03 -0400, Shapira, Yoav wrote:

Howdy,
This is a common problem, and you have several options.
>The logging works fine. The problem is specifying the location of the
log
>file.
>I use log4j.xml to configure log4j. In there I have to specify the
location
>of the
>log file as absolute path. This creates a problem because we have to
edit
You don't have to specify the path as absolute: it can be relative (to
the working directory), and it can contain environment variables.
>log4j.xml
>during each deployment of our application to edit the location of the
log
>file.
Another option is to automate this by copying the log4j.xml file with
filtering="true" in Ant.  In log4j.xml you'd have a token value for the
log file path, e.g. @logFilePath@, and when deploying you'd have Ant
replace this value with a value coming from an Ant property.
>I attempted to solve the problem by adding the following code in a
utility
>class
>
>   rootLogger = Logger.getRootLogger();
>   FileAppender fp = (FileAppender)
>rootLogger.getAppender("LOGFILE");
This is yet another option, the pure programmatic way.  I find this
useful some time, but cleaner if you create the appender
programmatically as well, i.e.
Layout l = ...
String logFilePath = 
Appender app = new FileAppder(l, logFilePath);
Logger.getRootLogger().addAppender(app)
Yoav Shapira



This e-mail, including any attachments, is a confidential business 
communication, and may contain information that is confidential, 
proprietary and/or privileged.  This e-mail is intended only for the 
individual(s) to whom it is addressed, and may not be saved, copied, 
printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your 
computer system and notify the sender.  Thank you.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Larry Young
The Dalmatian Group
www.dalmatian.com 



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


Re: Location of log files with Tomcat

2003-08-25 Thread Louise Pryor

On Monday, August 25, 2003 at 2:50:25 PM, Shapira, Yoav wrote:

>>initialization servlet  that goes through the log4j.properties file
>>making all the file locations be relative to my web app directory. The
>>code is listed below.

SY> Consider putting this code in a ServletContextListener's
SY> contextInitialized() method, instead of a servlet's init() method, as
SY> the latter can get called multiple times at the container's behest.

OK. I haven't come across a ServletContextListener before, so I'll
look it up and work out what it does.



SY> Keep in mind prefix will be null if you're running out of a packed .war
SY> file.

This just won't happen, as I can't deploy using a war. I have to
unpack the files by hand into my public_html directory.



SY> Instead of doing this whole property replacement scheme, why not just
SY> specify a system-property based file name in your log4j configuration
SY> file, e.g.
SY> log4j.MyAppender.File=${CATALINA_HOME}/logs/myLog.txt

As I said, I don't have any access at all to the ${CATALINA_HOME}
directory. When I do a getRealPath("/") in my webapp the result is
/home/myName/public_html/. For obvious reasons I don't want to hard
code that in anywhere. I am not even sure that say
${CATALINA_HOME}/webapps/myName/ would work, given the getRealPath
behaviour. What I would really like is a foolproof way of specifying a
file in my webapp directory structure in the log4j configuration file,
which would work whatever weird configuration my hosting provider has
used for Tomcat.


Louise
-- 
Louise Pryor
http://www.louisepryor.com



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



Re: Location of log files with Tomcat

2003-08-25 Thread Ceki Gülcü
I think there is an easier way. You can use log4j's variable
substitution mechanism:
All option values admit variable substitution. The syntax of variable
substitution is similar to that of Unix shells. The string between an
opening "${" and closing "}" is interpreted as a key. The value of the
substituted variable can be defined as a system property or in the
configuration file itself. The value of the key is first searched in
the system properties, and if not found there, it is then searched in
the configuration file being parsed. The corresponding value replaces
the ${variableName} sequence. For example, if java.home system
property is set to /home/xyz, then every occurrence of the sequence
${java.home} will be interpreted as /home/xyz.
HTH,

At 09:20 AM 8/25/2003 +0100, Louise Pryor wrote:
My web site is on a shared host, so I don't have access to the
$CATALINA_HOME/logs directory. In fact, I don't even know where the
host thinks the directory of my web site is (I see it as being in
~/public_html  ). I'm using log4j as my logging mechanism (directly
rather than through commons logging) and have some code in an
initialization servlet  that goes through the log4j.properties file
making all the file locations be relative to my web app directory. The
code is listed below.
My questions are:
- Is this a reasonable way of doing things?
- Is there a better way?
Thanks for any help on this

Louise
--
Louise Pryor
http://www.louisepryor.com


public void init() {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
Properties props = new Properties();
Enumeration enum;
String pName, pVal;
if (file != null) {
try {
FileInputStream istream = new FileInputStream(prefix+file);
props.load(istream);
istream.close();
}
catch (IOException e) {
LogLog.error("Could not read configuration file ["+
 prefix+file+"].", e);
LogLog.error("Ignoring configuration file [" +
 prefix+file+"].");
return;
}
// go through the properties looking for appender files.
// add the prefix onto them
for ( enum = props.propertyNames(); enum.hasMoreElements(); ) {
pName = (String ) enum.nextElement();
if ( pName.startsWith("log4j.appender.") &&
 pName.endsWith(".File")) {
pVal = props.getProperty(pName);
props.setProperty(pName, prefix+pVal);
} // end of if ()
} // end of for ()
PropertyConfigurator.configure(props);

} else {
BasicConfigurator.configure();
}
}
--
Ceki For log4j documentation consider "The complete log4j manual"
 ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp


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


RE: Location of log files with Tomcat

2003-08-25 Thread Shapira, Yoav

Howdy,

>initialization servlet  that goes through the log4j.properties file
>making all the file locations be relative to my web app directory. The
>code is listed below.

Consider putting this code in a ServletContextListener's
contextInitialized() method, instead of a servlet's init() method, as
the latter can get called multiple times at the container's behest.

>My questions are:
>- Is this a reasonable way of doing things?
>- Is there a better way?


>public void init() {
>String prefix = getServletContext().getRealPath("/");

Keep in mind prefix will be null if you're running out of a packed .war
file.

>
>for ( enum = props.propertyNames(); enum.hasMoreElements();
) {
>pName = (String ) enum.nextElement();
>if ( pName.startsWith("log4j.appender.") &&
> pName.endsWith(".File")) {

Instead of doing this whole property replacement scheme, why not just
specify a system-property based file name in your log4j configuration
file, e.g.
log4j.MyAppender.File=${CATALINA_HOME}/logs/myLog.txt

The above strategy and similar ones have been discussed on this list in
the past.  You can search the archives for more information and
examples.

Yoav Shapira




This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


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



Location of log files with Tomcat

2003-08-25 Thread Louise Pryor
My web site is on a shared host, so I don't have access to the
$CATALINA_HOME/logs directory. In fact, I don't even know where the
host thinks the directory of my web site is (I see it as being in
~/public_html  ). I'm using log4j as my logging mechanism (directly
rather than through commons logging) and have some code in an
initialization servlet  that goes through the log4j.properties file
making all the file locations be relative to my web app directory. The
code is listed below.

My questions are:
- Is this a reasonable way of doing things?
- Is there a better way?

Thanks for any help on this

Louise
-- 
Louise Pryor 
http://www.louisepryor.com



public void init() {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
Properties props = new Properties();
Enumeration enum;
String pName, pVal;

if (file != null) {
try {
FileInputStream istream = new FileInputStream(prefix+file);
props.load(istream);
istream.close();
}
catch (IOException e) {
LogLog.error("Could not read configuration file ["+
 prefix+file+"].", e);
LogLog.error("Ignoring configuration file [" +
 prefix+file+"].");
return;
}
// go through the properties looking for appender files.
// add the prefix onto them

for ( enum = props.propertyNames(); enum.hasMoreElements(); ) {
pName = (String ) enum.nextElement();
if ( pName.startsWith("log4j.appender.") &&
 pName.endsWith(".File")) {
pVal = props.getProperty(pName);
props.setProperty(pName, prefix+pVal);
} // end of if ()
} // end of for ()

PropertyConfigurator.configure(props);
 
} else {
BasicConfigurator.configure();
}
}



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



Re: Location of log files

2003-08-14 Thread Ceki Gülcü
Have you tried using system properties? Log4j performs variable 
substitution in XML files as well.

At 01:44 PM 8/5/2003 -0400, Grum Ketema wrote:
Hello

I could not find a simple solution
to this problem. I deploy a web application (a War file) in
a web server (iplanet) and an ejb application ( an ear file) in
OAS (oracle application server). I want to use log4j in both applications.
The logging works fine. The problem is specifying the location of the log
file.
I use log4j.xml to configure log4j. In there I have to specify the location
of the
log file as absolute path. This creates a problem because we have to edit
log4j.xml
during each deployment of our application to edit the location of the log
file.
I attempted to solve the problem by adding the following code in a utility
class
rootLogger = Logger.getRootLogger();
FileAppender fp = (FileAppender) 
rootLogger.getAppender("LOGFILE");
String fileName = fp.getFile();
String dir = getOracleRootDir();
if (dir!=null) {
StringBuffer logFilePath = new 
StringBuffer(dir);

logFilePath.append(File.separator+"log"+File.separator+fileName);
fp.setFile(logFilePath.toString());
fp.activateOptions();
}
which is kind of clumsy. Is there any way of specifying the location of the
log
file without editing log4j.xml (e.g. programmatically or otherwise)
Regards,
Grum
--
Ceki For log4j documentation consider "The complete log4j manual"
 ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp


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


Location of log files

2003-08-14 Thread Grum Ketema
Hello

I could not find a simple solution
to this problem. I deploy a web application (a War file) in
a web server (iplanet) and an ejb application ( an ear file) in
OAS (oracle application server). I want to use log4j in both applications.
The logging works fine. The problem is specifying the location of the log
file.
I use log4j.xml to configure log4j. In there I have to specify the location
of the
log file as absolute path. This creates a problem because we have to edit
log4j.xml
during each deployment of our application to edit the location of the log
file.
I attempted to solve the problem by adding the following code in a utility
class

rootLogger = Logger.getRootLogger();
FileAppender fp = (FileAppender) rootLogger.getAppender("LOGFILE");
String fileName = fp.getFile();
String dir = getOracleRootDir();
if (dir!=null) {
StringBuffer logFilePath = new StringBuffer(dir);

logFilePath.append(File.separator+"log"+File.separator+fileName);
fp.setFile(logFilePath.toString());
fp.activateOptions();
}

which is kind of clumsy. Is there any way of specifying the location of the
log
file without editing log4j.xml (e.g. programmatically or otherwise)

Regards,
Grum


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



RE: Location of log files

2003-08-06 Thread Shapira, Yoav

Howdy,
This is a common problem, and you have several options.

>The logging works fine. The problem is specifying the location of the
log
>file.
>I use log4j.xml to configure log4j. In there I have to specify the
location
>of the
>log file as absolute path. This creates a problem because we have to
edit

You don't have to specify the path as absolute: it can be relative (to
the working directory), and it can contain environment variables.

>log4j.xml
>during each deployment of our application to edit the location of the
log
>file.

Another option is to automate this by copying the log4j.xml file with
filtering="true" in Ant.  In log4j.xml you'd have a token value for the
log file path, e.g. @logFilePath@, and when deploying you'd have Ant
replace this value with a value coming from an Ant property.

>I attempted to solve the problem by adding the following code in a
utility
>class
>
>   rootLogger = Logger.getRootLogger();
>   FileAppender fp = (FileAppender)
>rootLogger.getAppender("LOGFILE");

This is yet another option, the pure programmatic way.  I find this
useful some time, but cleaner if you create the appender
programmatically as well, i.e.
Layout l = ...
String logFilePath = 
Appender app = new FileAppder(l, logFilePath);
Logger.getRootLogger().addAppender(app)

Yoav Shapira



This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


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



RE: controlling the location of log files

2003-02-20 Thread Steve Cohen
Thanks, this was just what I needed.

As far as JRun goes, there is already a variable defined called
jrun.rootdir and their logs directory is a subdirectory of that, so this
turns out to be very easy to implement with your suggestion of
referencing system variables.

-Original Message-
From: Steve Ebersole [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, February 19, 2003 9:03 PM
To: Log4J Users List
Subject: Re: controlling the location of log files


As with all java processes, a relative file path will be interpreted as
relative from the current working directory (i.e., the directory from
which the process was created).  However, that is not always the
directory you were in when you ran the command (weblogic, for example,
CDs to its domain-specific directory before launching the server).

Don't have much experience with JRun, so I cannot say for sure how it
works.

However, there is an option to use variable replacement within the log4j
config file.  The basic jist would be to define a java System variable
(either using a -D option on the command line used to start the process,
or explicitly calling System.setProperty() in your code) and then
referencing that variable in the config.  So for example:
1) start your process with java -Dlog4j.log.dir=
2) use ${log4j.log.dir} where you want to define the relative path; like
${log4j.log.dir}/myLogFile.log


Just FYI, if you decide to use this approach and try to use the
System.setProperty call, make sure the System.setProperty call is done
before log4j gets configured.

HTH


- Original Message -
From: "Steve Cohen" <[EMAIL PROTECTED]>
To: "Log4J Users List" <[EMAIL PROTECTED]>
Sent: Wednesday, February 19, 2003 5:19 PM
Subject: controlling the location of log files


Is there a way, without writing system-dependent absolute paths in the
log4j configuration file to control where log4j puts the logs?  In other
words, to what is a relative path passed to log4j relative?  Is this
entirely container-dependent?  If so, can someone with experience with
log4j under JRun4 tell me how (system-independently) to make the logfile
come up in the jrun/logs directory?
---
Steve Cohen
Sr. Software Engineer
Sportvision Inc.
[EMAIL PROTECTED]
http://www.sportvision.com

Please note: As a result of the merger of
Ignite Sports and Sportvision, my email address
has changed to [EMAIL PROTECTED]


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



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


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




Re: controlling the location of log files

2003-02-19 Thread Steve Ebersole
As with all java processes, a relative file path will be interpreted as
relative from the current working directory (i.e., the directory from which
the process was created).  However, that is not always the directory you
were in when you ran the command (weblogic, for example, CDs to its
domain-specific directory before launching the server).

Don't have much experience with JRun, so I cannot say for sure how it works.

However, there is an option to use variable replacement within the log4j
config file.  The basic jist would be to define a java System variable
(either using a -D option on the command line used to start the process, or
explicitly calling System.setProperty() in your code) and then referencing
that variable in the config.  So for example:
1) start your process with java -Dlog4j.log.dir=
2) use ${log4j.log.dir} where you want to define the relative path; like
${log4j.log.dir}/myLogFile.log


Just FYI, if you decide to use this approach and try to use the
System.setProperty call, make sure the System.setProperty call is done
before log4j gets configured.

HTH


- Original Message -
From: "Steve Cohen" <[EMAIL PROTECTED]>
To: "Log4J Users List" <[EMAIL PROTECTED]>
Sent: Wednesday, February 19, 2003 5:19 PM
Subject: controlling the location of log files


Is there a way, without writing system-dependent absolute paths in the
log4j configuration file to control where log4j puts the logs?  In other
words, to what is a relative path passed to log4j relative?  Is this
entirely container-dependent?  If so, can someone with experience with
log4j under JRun4 tell me how (system-independently) to make the logfile
come up in the jrun/logs directory?
---
Steve Cohen
Sr. Software Engineer
Sportvision Inc.
[EMAIL PROTECTED]
http://www.sportvision.com

Please note: As a result of the merger of
Ignite Sports and Sportvision, my email address
has changed to [EMAIL PROTECTED]


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



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




Re: controlling the location of log files

2003-02-19 Thread Jacob Kjome

You can set the logging location as a system variable and then set the 
system variable at server startup time or do it programmatically at runtime 
just before invoking configure().

For instance










You just set the Myapp.log.home system variable to whatever you 
require.  Now you never have to edit the log4j configuration file for any 
specific system.

Jake

At 05:19 PM 2/19/2003 -0600, you wrote:
Is there a way, without writing system-dependent absolute paths in the
log4j configuration file to control where log4j puts the logs?  In other
words, to what is a relative path passed to log4j relative?  Is this
entirely container-dependent?  If so, can someone with experience with
log4j under JRun4 tell me how (system-independently) to make the logfile
come up in the jrun/logs directory?
---
Steve Cohen
Sr. Software Engineer
Sportvision Inc.
[EMAIL PROTECTED]
http://www.sportvision.com

Please note: As a result of the merger of
Ignite Sports and Sportvision, my email address
has changed to [EMAIL PROTECTED]


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



controlling the location of log files

2003-02-19 Thread Steve Cohen
Is there a way, without writing system-dependent absolute paths in the
log4j configuration file to control where log4j puts the logs?  In other
words, to what is a relative path passed to log4j relative?  Is this
entirely container-dependent?  If so, can someone with experience with
log4j under JRun4 tell me how (system-independently) to make the logfile
come up in the jrun/logs directory?
---
Steve Cohen
Sr. Software Engineer
Sportvision Inc.
[EMAIL PROTECTED]
http://www.sportvision.com

Please note: As a result of the merger of 
Ignite Sports and Sportvision, my email address 
has changed to [EMAIL PROTECTED]


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