Re: set the placeholder in the log4j.properties file
Thanks for all you guys. I will have a try. 2010/12/30 Tushar Kapila > I think for most apps you would want all logs to go to file so you can > see start up exceptions. Only place you might not mind missing this is > when no app specific common code runs before this servlet inits. > So my advice is customize the log4j xml in file system per install. > That way all logs will be in file. > > On 12/29/10, Jacob Kjome wrote: > > Log4j will attempt to auto-configure itself by looking for "log4j.xml" > and > > then > > "log4j.properties" in the root of the claspath upon the first call to > > getLogger(). > > And yes, this may very well be before your init servlet runs. Note that > > the new > > configuration (done manually in the init servlet) will have things > > configured as > > you want them. > > > > There is a solution. You can set system properties > > > > -Dapppath=/my/logging/directory > > > > And, optionally > > -Dlog4j.configuration=file:///path/to/log4j.properties > > > > > > That said, you could just place a minimal config file in the classpath > > pointing > > all logging to the Console and then let your init servlet configure the > > preferred > > config file as you are doing. I guess it all depends on how important it > is > > for > > you to get all logging to your preferred file, even logging that occurs > > prior to > > your init servlet running. > > > > > > Jake > > > > On 12/27/2010 12:26 AM, maven apache wrote: > >> Hi: > >> > >> I want the logs created by log4j put under the app dir,so I set the > >> placeholder in the log4j.properties: > >> > >> # chartstdout is set to be a ConsoleAppender. > >> log4j.appender.chartstdout=org.apache.log4j.ConsoleAppender > >> log4j.appender.chartstdout.layout=org.apache.log4j.PatternLayout > >> log4j.appender.chartstdout.layout.ConversionPattern=%-4r [%t] %-5p %l %x > - > >> %m%n > >> > >> > >> log4j.appender.chartfileout=org.apache.log4j.FileAppender > >> log4j.appender.chartfileout.File=${apppath}/logs/log.html > >> log4j.appender.chartfileout.Append=true > >> log4j.appender.chartfileout.layout=com.test.util.CustomHTMLLayout > >> > >> log4j.rootLogger=debug, chartstdout,chartfileout > >> > >> Then in my servlet whose "load-on-startup" attribute is "0" I set the > >> property "apppath",but it does not work. > >> It seems that the log4j read the log4j.properties and config the log > >> before > >> I modify the property. > >> public void init() { > >> DbManager.init(); > >> // log > >> String context = > >> getServletConfig().getServletContext().getRealPath("/"); > >> Properties p = new Properties(); > >> p.setProperty("apppath", context); > >> try { > >> > >> p.load(InitServlet.class.getResourceAsStream("/log4j.properties")); > >> } catch (IOException e) { > >> e.printStackTrace(); > >> } > >> PropertyConfigurator.configure(p); > >> } > >> > >> > >> > >> Of course,I can rename the log4j.properties,then the log4j will not find > >> the > >> file but I can. However some other libs which I used in my appliction > >> require log4j also,they need the log4j.properties to generate there > logs. > >> > >> Any ideas? > >> > > > > - > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > -- > Sent from my mobile device > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > >
set the placeholder in the log4j.properties file
Hi: I want the logs created by log4j put under the app dir,so I set the placeholder in the log4j.properties: # chartstdout is set to be a ConsoleAppender. log4j.appender.chartstdout=org.apache.log4j.ConsoleAppender log4j.appender.chartstdout.layout=org.apache.log4j.PatternLayout log4j.appender.chartstdout.layout.ConversionPattern=%-4r [%t] %-5p %l %x - %m%n log4j.appender.chartfileout=org.apache.log4j.FileAppender log4j.appender.chartfileout.File=${apppath}/logs/log.html log4j.appender.chartfileout.Append=true log4j.appender.chartfileout.layout=com.test.util.CustomHTMLLayout log4j.rootLogger=debug, chartstdout,chartfileout Then in my servlet whose "load-on-startup" attribute is "0" I set the property "apppath",but it does not work. It seems that the log4j read the log4j.properties and config the log before I modify the property. public void init() { DbManager.init(); // log String context = getServletConfig().getServletContext().getRealPath("/"); Properties p = new Properties(); p.setProperty("apppath", context); try { p.load(InitServlet.class.getResourceAsStream("/log4j.properties")); } catch (IOException e) { e.printStackTrace(); } PropertyConfigurator.configure(p); } Of course,I can rename the log4j.properties,then the log4j will not find the file but I can. However some other libs which I used in my appliction require log4j also,they need the log4j.properties to generate there logs. Any ideas?
Re: does log4j support wildcard
My fault, I think it is my express problem,maybe I mean the placeholder rather than the wildcard. 2010/12/6 JOSE L MARTINEZ-AVIAL > user.dir is a system properties, as defined in > http://download.oracle.com/javase/1.4.2/docs/api/java/lang/System.html > > You can setup dinamically other variable and use it. But you are right in > the sense that it is not a wildcard. What I'm wondering is in what context > makes sense to use a wildcard when defining the path where a file will be > written. What happens if there is more than one path that can fit the > wildcard? which one is used? > > 2010/12/6 Stadelmann Josef > > > But is that given solution a real wildcard? "${user.dir}/../logs/eco" I > > guess no. > > > > 1.${user.dir} muts be define dpreviously or it comes implementation > > dependent as "" > > 2. and this may lead to errors > > 3. then /../ directs to go up in the tree one level > > 4. before you go down in the tree to /logs/eco > > > > Given ${user.dir} is not defined when used, what is the outcome? > > > > ${user.dir} must be a property may be a macro which is defined prior to > > beeing used. > > > > But if you say C:\ > dir stade*.doc then the "*" is a true wildcard > saying > > that anything wild after "stade" can stay unless the dot is received from > > where on only files with a doc extension will be listed in the directory > > command. > > > > So > > stade1.doc > > stade2.doc > > stadeX.doc > > but not > > stadeN.dot > > > > are listed > > > > Also id ${user.dior} would be something like 112345 (as possible for > > wildcards) > > Would that make sense in the wanted use and context? No, so I would not > > refer to > > ${user.dir} as to a widlcard, even ${user.dir} migth be defined to a > valid > > user > > On most OS and platforms, but have to lead/form part of a TRUE PATH in > the > > end. > > > > While this is not necessary for a true wildcard character. > > > > Or do we have to re-define what wildcards are? > > > > Josef > > > > > > > > > > -Ursprüngliche Nachricht- > > Von: maven apache [mailto:apachemav...@gmail.com] > > Gesendet: Dienstag, 30. November 2010 11:10 > > An: Log4J Users List > > Betreff: Re: does log4j support wildcard > > > > 2010/11/30 JOSE L MARTINEZ-AVIAL > > > > > For example, to use the user dir in the path: > > > log4j.appender.ECO_LOG.File=${user.dir}/../logs/eco.log > > > > > > > :) Thank you very much. > > > > > > > > > > > > > > 2010/11/30 maven apache > > > > > > > 2010/11/30 JOSE L MARTINEZ-AVIAL > > > > > > > > > A system propertie will do. I use it, and works perfectly. > > > > > > > > > Thanks, I will have a try. :) > > > > > > > > > > > > > > 2010/11/30 maven apache > > > > > > > > > > > 2010/11/30 Stadelmann Josef > > > > > > > > > > > > > How can you define a destination with a widlcard? > > > > > > > Think : copy file-a.txt to {widlcard} > > > > > > > where wildcard is not defined when copy starts executing, > > > > > > > and then tell me where file-a.txt is after the copy completes? > > > > > > > > > > > > > > My question is where to define the . > > > > > > > > > > > > > > > > > > > Maybe you think of as shown below! > > > > > > > # R is a rolling file appender --- not used yet / no need to > > parse > > > > > > > log4j.appender.R=org.apache.log4j.RollingFileAppender > > > > > > > log4j.appender.R.Append=true > > > > > > > log4j.appender.R.File=${}logs/tomcat.log > > > > > > > log4j.appender.R.MaxFileSize=2MB > > > > > > > log4j.appender.R.MaxBackupIndex=10 > > > > > > > log4j.appender.R.layout=org.apache.log4j.PatternLayout > > > > > > > log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n > > > > > > > > > > > > > > now xxxx is your exported environment variable or a logical > > > > > > > and it needs to be defined unless your log will be written at > > > > > > > > > > >
Re: does log4j support wildcard
2010/11/30 JOSE L MARTINEZ-AVIAL > For example, to use the user dir in the path: > log4j.appender.ECO_LOG.File=${user.dir}/../logs/eco.log > :) Thank you very much. > > > > 2010/11/30 maven apache > > > 2010/11/30 JOSE L MARTINEZ-AVIAL > > > > > A system propertie will do. I use it, and works perfectly. > > > > > Thanks, I will have a try. :) > > > > > > > > 2010/11/30 maven apache > > > > > > > 2010/11/30 Stadelmann Josef > > > > > > > > > How can you define a destination with a widlcard? > > > > > Think : copy file-a.txt to {widlcard} > > > > > where wildcard is not defined when copy starts executing, > > > > > and then tell me where file-a.txt is after the copy completes? > > > > > > > > > > My question is where to define the . > > > > > > > > > > > > > Maybe you think of as shown below! > > > > > # R is a rolling file appender --- not used yet / no need to parse > > > > > log4j.appender.R=org.apache.log4j.RollingFileAppender > > > > > log4j.appender.R.Append=true > > > > > log4j.appender.R.File=${}logs/tomcat.log > > > > > log4j.appender.R.MaxFileSize=2MB > > > > > log4j.appender.R.MaxBackupIndex=10 > > > > > log4j.appender.R.layout=org.apache.log4j.PatternLayout > > > > > log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n > > > > > > > > > > now is your exported environment variable or a logical > > > > > and it needs to be defined unless your log will be written at > > > > > > > > > > Yes,so it means the can be set in the System.properties? > > > > > > > > > > > > > ./logs/tomcat.log > > > > > > > > > > Josef > > > > > > > > > > > > > > > > > > > > -Ursprüngliche Nachricht- > > > > > Von: maven apache [mailto:apachemav...@gmail.com] > > > > > Gesendet: Dienstag, 30. November 2010 00:31 > > > > > An: Log4J Users List > > > > > Betreff: Re: does log4j support wildcard > > > > > > > > > > 1. log4j.appender.FILE=org.apache.log4j.FileAppender > > > > > 2. log4j.appender.FILE.File={}/file.log > > > > > > > > > > where the is the wildcard > > > > > > > > > > 2010/11/30 Scott Deboy > > > > > > > > > > > Can you clarify what you mean specifically by 'wildcard'? > > > > > > > > > > > > Scott > > > > > > > > > > > > On Mon, Nov 29, 2010 at 3:32 AM, maven apache < > > > apachemav...@gmail.com > > > > > > >wrote: > > > > > > > > > > > > > Hi: > > > > > > > Does log4j support wildcard? > > > > > > > > > > > > > > Is there a example? > > > > > > > > > > > > > > > > > > > > > > > > - > > > > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > > > > For additional commands, e-mail: > log4j-user-h...@logging.apache.org > > > > > > > > > > > > > > > > > > > >
Re: does log4j support wildcard
2010/11/30 JOSE L MARTINEZ-AVIAL > A system propertie will do. I use it, and works perfectly. > Thanks, I will have a try. :) > > 2010/11/30 maven apache > > > 2010/11/30 Stadelmann Josef > > > > > How can you define a destination with a widlcard? > > > Think : copy file-a.txt to {widlcard} > > > where wildcard is not defined when copy starts executing, > > > and then tell me where file-a.txt is after the copy completes? > > > > > > My question is where to define the . > > > > > > > Maybe you think of as shown below! > > > # R is a rolling file appender --- not used yet / no need to parse > > > log4j.appender.R=org.apache.log4j.RollingFileAppender > > > log4j.appender.R.Append=true > > > log4j.appender.R.File=${}logs/tomcat.log > > > log4j.appender.R.MaxFileSize=2MB > > > log4j.appender.R.MaxBackupIndex=10 > > > log4j.appender.R.layout=org.apache.log4j.PatternLayout > > > log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n > > > > > > now is your exported environment variable or a logical > > > and it needs to be defined unless your log will be written at > > > > > > Yes,so it means the can be set in the System.properties? > > > > > > > ./logs/tomcat.log > > > > > > Josef > > > > > > > > > > > > -Ursprüngliche Nachricht- > > > Von: maven apache [mailto:apachemav...@gmail.com] > > > Gesendet: Dienstag, 30. November 2010 00:31 > > > An: Log4J Users List > > > Betreff: Re: does log4j support wildcard > > > > > > 1. log4j.appender.FILE=org.apache.log4j.FileAppender > > > 2. log4j.appender.FILE.File={}/file.log > > > > > > where the is the wildcard > > > > > > 2010/11/30 Scott Deboy > > > > > > > Can you clarify what you mean specifically by 'wildcard'? > > > > > > > > Scott > > > > > > > > On Mon, Nov 29, 2010 at 3:32 AM, maven apache < > apachemav...@gmail.com > > > > >wrote: > > > > > > > > > Hi: > > > > > Does log4j support wildcard? > > > > > > > > > > Is there a example? > > > > > > > > > > > > > > > - > > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > > > For additional commands, e-mail: log4j-user-h...@logging.apache.org > > > > > > > > >
Re: does log4j support wildcard
2010/11/30 Stadelmann Josef > How can you define a destination with a widlcard? > Think : copy file-a.txt to {widlcard} > where wildcard is not defined when copy starts executing, > and then tell me where file-a.txt is after the copy completes? > > My question is where to define the . > Maybe you think of as shown below! > # R is a rolling file appender --- not used yet / no need to parse > log4j.appender.R=org.apache.log4j.RollingFileAppender > log4j.appender.R.Append=true > log4j.appender.R.File=${}logs/tomcat.log > log4j.appender.R.MaxFileSize=2MB > log4j.appender.R.MaxBackupIndex=10 > log4j.appender.R.layout=org.apache.log4j.PatternLayout > log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n > > now is your exported environment variable or a logical > and it needs to be defined unless your log will be written at > > Yes,so it means the can be set in the System.properties? > ./logs/tomcat.log > > Josef > > > > -Ursprüngliche Nachricht- > Von: maven apache [mailto:apachemav...@gmail.com] > Gesendet: Dienstag, 30. November 2010 00:31 > An: Log4J Users List > Betreff: Re: does log4j support wildcard > > 1. log4j.appender.FILE=org.apache.log4j.FileAppender > 2. log4j.appender.FILE.File={}/file.log > > where the is the wildcard > > 2010/11/30 Scott Deboy > > > Can you clarify what you mean specifically by 'wildcard'? > > > > Scott > > > > On Mon, Nov 29, 2010 at 3:32 AM, maven apache > >wrote: > > > > > Hi: > > > Does log4j support wildcard? > > > > > > Is there a example? > > > > > > > - > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org > >
Re: does log4j support wildcard
1. log4j.appender.FILE=org.apache.log4j.FileAppender 2. log4j.appender.FILE.File={}/file.log where the is the wildcard 2010/11/30 Scott Deboy > Can you clarify what you mean specifically by 'wildcard'? > > Scott > > On Mon, Nov 29, 2010 at 3:32 AM, maven apache >wrote: > > > Hi: > > Does log4j support wildcard? > > > > Is there a example? > > >
does log4j support wildcard
Hi: Does log4j support wildcard? Is there a example?