Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how i change log file names including day 1

Status
Not open for further replies.

fuadhamidov

Programmer
Sep 22, 2003
98
TR
hi

i use log4j. my all error logs are in same log file. its size increases day by day :)) . i want to change its name every day automatically like apache tomcat log files.

is there any way?
how?
 
hi

until now i have used FileAppender ( not RollingFileAppender ) instead of DailyRollingFileAppender. i have looked from the link above both extends FileAppender. i have changed my configuration file ( error_outletim_logger.lcf )as bellow

log4j.rootCategory=, A1
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=c:\\.......\\WEB-INF\\logs\\error_outletim.log
log4j.appender.A1.DatePattern='.'yyyy-MM-dd
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] (%x) - %m\n

( i have changed FileAppender to DailyRollingFileAppender and add DatePattern)

but i dont know should i change ( or add ) some thing to my code

String configFile = Parameters.ROOT_DIR + "\\conf\\error_outletim_logger.lcf";
PropertyConfigurator.configure(configFile);
Category cat = Category.getInstance("outletim");
cat.error(line);
 
ok

i should have changed my log4j with new one
after i changed, it is OK
 
HI

My log4j file is like this

log4j.rootCategory=, A1
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=c:\\.......\\WEB-INF\\logs\\error_outletim.log
log4j.appender.A1.DatePattern='.'yyyy-MM-dd
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] (%x) - %m\n

when stated the JRun 4. After the start the message is like this...

Server SERVERNAME ready (startup time: 5 seconds)
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: c:\.......\WEB-INF\logs\error_outletim.log (The system cannot find the path specified)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:174)
at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
at java.io.FileWriter.<init>(FileWriter.java:61)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:284)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:239)
at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:259)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:247)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:123)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:87)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:637)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:595)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:502)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:410)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:341)
at com.ifp.util.Log.configure(Unknown Source)
at com.ifp.util.Log.init(Unknown Source)
at com.ifp.util.Log.<init>(Unknown Source)
at com.ifp.business.ejb.IFPBaseSessionBean.<clinit>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:306)
at java.lang.Class.newInstance(Class.java:259)
at jrun.ejb.SessionFactory.createInstance(SessionFactory.java:60)
at jrun.ejb.EJBFactory.createPooledInstance(EJBFactory.java:34)
at jrun.ejb.SimpleInstancePool.run(SimpleInstancePool.java:186)
at jrunx.scheduler.SchedulerService.invokeRunnable(SchedulerService.java:223)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
log4j:ERROR Either Filename or DatePattern options are not set for [A1].


Please advice and I tried changing the dir where I need the log4j log file but nothing improved than just writing the log file in
C:\JRun4\bin

Please correct me and thanks in advance
 
i have faced the same exception.

the error is that. when any exception has occured the logger (log.jar) wants to save the log message into a file you have specifed .lcf file.

.lcf and .log file dir can be defferent.

As i understand from excepton messege you get

/*
java.io.FileNotFoundException: c:\.......\WEB-INF\logs\error_outletim.log (The system cannot find the path specified)
*/

the logger can't find the path c:\.......\WEB-INF\logs\error_outletim.log so an exception occur. the file (error_outletim.log) may or may not be created but the folder(c:\.......\WEB-INF\logs\) should be.

so

you may want to try this

create a new folder under c:\JRun4, name it as logs

log4j.rootCategory=, A1
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=c:\\JRun4\\logs\\error_myproject.log
log4j.appender.A1.DatePattern='.'yyyy-MM-dd
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] (%x) - %m\n
 
Thanks
It worked fine. But now I am in search of generating an log file upto say 10K or 200K. then after the max size of the log file, create another file withsame name and with current date on the end of the file name.
Your idea to proceed in right direction is more important...


p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top