RE: Location of log files
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
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
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
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
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
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
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
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
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]
Re: Location of log files
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]
RE: Location of log files
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]