0

based on this question

I tried to redirect Tomcat console output to a text file and it works fine for my web application, but the problem is, it overwrites everytime when Tomcat started. I need to create a log file (file name along with date and time) and should create new file everytime when Tomcat, ie starts should not overwrite. and the file name should also include date and time

please, help me how can i do this?

tomcat 6.0,

windows environment

catalina.bat run > log.txt 2>&1

i put this inside start.bat (start.bat: sets catalina_home and java_home and starts startup.bat which starts the server and redirects the console output by catalina.bat run > log.txt 2>&1 )

I also tried log4j

`log4j.rootLogger = INFO, FILE

log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender

log4j.appender.FILE.File=C:\path\logs\log4j.txt

log4j.appender.FILE.ImmediateFlush=true

log4j.appender.FILE.Threshold=debug

log4j.appender.FILE.Append=true

log4j.appender.FILE.DatePattern='.' yyyy-MM-dd-a

log4j.appender.FILE.layout=org.apache.log4j.PatternLayout

log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n `

but this writes the info only from Docx4j Api that i use for creating word doc. not writing sys out and sys err values ie system.out.println() values. I also tried like this but didnt work

Community
  • 1
  • 1
Ram
  • 33
  • 2
  • 8
  • Take a look at the [Log4j](http://logging.apache.org/log4j/1.2/) Library. – christopher Feb 20 '14 at 12:15
  • Hey Christopher, I tried also using log4j but didnt work, i am not sure if i did it in correct way.. i tried like this [http://stackoverflow.com/questions/5942478/how-to-make-log4j-record-to-a-file-and-print-to-console] but it didnt prints me any system outputs – Ram Feb 20 '14 at 13:08

1 Answers1

0

You can try configuring Log4j via code instead of using xml or properties file.

Take a look at Configuring Log4j Loggers Programmatically

Community
  • 1
  • 1
Gaurav Goel
  • 325
  • 2
  • 14