Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

log rotate for Windows

 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any utility tool to rotate catalina.out for windows?

On the web site, there are suggestions for Unix/Linux, but not for windows:

/log/tomcat/catalina.out{
copytruncate
daily
rotate 10
compress
missingok
size 1KB

}

 
Sheriff
Posts: 22002
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if it'll work with Tomcat, but with Apache's HTTPD server I've used Cronolog successfully.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure about catalina.out, but if you define loggers in your application, using log4j for example, then you can set up a RollingFileAppender which has a max file size and it will create new files when the limit is reached. In this case no output from your application goes into catalina.out, so you probably don't need to rotate it.
 
author
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I integrated logback into tomcat7:

https://github.com/grgrzybek/tomcat-slf4j-logback

 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I search online, I do not see any instruction how to use Cronolog. I click on cronolog.exe, but nothing happens.
 
Rob Spoor
Sheriff
Posts: 22002
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a command line tool. That means that it does not have a user interface, so double clicking indeed does nothing. Open a command prompt, go to the folder where you've unpacked Cronolog, then type "cronolog --help".

And you really couldn't find this page? It's on Cronolog's own homepage.
 
author
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three ways though which log rotation can be done on windows
1. Write a batch script and rotate the logs.
2. Rotate the logs using log4j,( you need to create an file appender in log4j.xml )
3. By default tomcat 7 comes with logging api called JULI( you need to create an file appender in logging. Properties )

log4j or JULI both are used widely across industries
 
Rob Spoor
Sheriff
Posts: 22002
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

tanuj khare wrote:1. Write a batch script and rotate the logs.


Is that actually possible? At my previous employer, we used Tomcat 6.something and it locked the log files for System.out and System.err until Tomcat was restarted. That usually meant the same two files being used for at least a month. After a Tomcat restart it would create two new files, at which time the first two files were finally "free".
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how to use log4j to rotate the log file by size?
 
Mick Knutson
author
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Helen Ma wrote:But how to use log4j to rotate the log file by size?



You can do:
 
tanuj khare
author
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While doing the log rotation two things you should have to keep in mind
1. If your site have high traffic then go with size based log rotation. only disadvantage with approach is “in case of real time issues, logs get filled very quickly and there is chance of that logs getting over written “
2. If your application have normal user traffic then go for everyday log rotation
Properties of second method mentioned below
log4j.rootLogger=INFO, CATALINA

# Define all the appenders
log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.File=/var/log/tomcat7/catalina.out
log4j.appender.CATALINA.Append=true
log4j.appender.CATALINA.Encoding=UTF-8

# Roll-over the log once per day
log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd-HH-mm'.log'
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern =%d{HH:mm:ss} %5p [%t] - %m%n


 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to log4j. In which tomcat file I should put the log4j.appender ?
My purpose is to rotate tomcat log file.
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, I figured that the log4j.appender should be put in the log4j.properties file.
I put :
log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.MAXFileSize = 2KB

But it is still rotating based on the date of today, not base on size.
 
tanuj khare
author
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which class you are using ?
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have a class.
I created a log4j.properties file and put the code there.
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, sorry to be a month late, but did you ever figure this out? It looks to me like the problem is you used org.apache.log4j.DailyRollingFileAppender, which does in fact roll by day, and doesn't (I believe) take a MaxFileSize parameter. You should be using org.apache.log4j.RollingFileAppender.
 
If you're gonna buy things, buy this thing and I get a fat kickback:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic