How to truncate Tomcat Catalina.out log to 3 months back - java

My company wants us to save logs from the past 3 months. Catalina.out is getting too large on the linux server (Red hat). How can I remove everything in the log except for the last 3 months in the ONE catalina.out file.

I had a requirement slightly similar to you case. This is how I tackled the requirement.
Add following Linux commands into Cron Scheduler
grep the required date stamp i.e. 2022-05-07 and write to new file
grep "2022-05-07" > 2022_05_07.log // write lines which matches the data stamp
wc -l 2022_05_07.log // outputs how many lines captured
Clear the log of catalina.out file without stopping tomcat with the command below.
sudo cat /dev/null > /opt/tomcat/apache-tomcat-9.0.37/logs/catalina.out
Make note it is not recommended to delete the catalina.out while tomcat is running.
It will keep on logging to catalina.out which is removed already (reference of the file is hold by the tomcat) hence the space will not be released. So you will need to restart the tomcat sever to release the space.

Related

When starting Apollo, run start Error reporting during up

pid - 808 just quit unexpectedly, please check logs under /opt/logs/100003171 and /tmp for more information![enter image description here][1]
lsLinHaiZhao ~/Desktop/apollo/apollo-configservice/target/apollo-configservice-2.0.0-SNAPSHOT-github/scripts (master)
$ sh startup.sh
mkdir: cannot create directory ‘/opt’: Permission denied
Windows new JAVA_HOME is: /c/PROGRA~1/Java/JDK18~1.0_4
2022年02月22日 16:18:17 ==== Starting ====
LOG_FOLDER /opt/logs/100003171/ does not exist. Falling back to /tmp
Started [808]
Waiting for server startup.
pid - 808 just quit unexpectedly, please check logs under /opt/logs/100003171 and /tmp for more information!
lsLinHaiZhao ~/Desktop/apollo/apollo-configservice/target/apollo-configservice-2.0.0-SNAPSHOT-github/scripts (master)
$
1.Database password cannot be used: special characters can be used to modify the database password!
2.If the database is not started, the same error will be reported. Restart the database!
3.Not here Configure the contents of relevant databases in the properties file or YML file, and comment out the unnecessary or redundant configuration information, and restart it!
There are three possible mistakes, each of which can lead to the above mistakes. Carefully examine your own problems. Using these three solutions can solve your problems!!!

Tomcat catalina.out is 40GB

I wonder why my spring project with tomcat server got catalina.out file with size 40GB. Any solutions, please.catalina.out reach 40 GB
catalina.out reaches such a large size because:
1- there might be many logging messages sent to console handler, and
2- also there is not any rotation of catalina.out (and no policy to remove older catalina.out).
First, as there might be some duplication and the messages in catalina.out , which could also be stored in *log messages too, I'd check if the contents of the log files (catalina.[DATE].log) are the same as those of catalina.out, if so then you can edit file conf/logging.properties and remove console handler
I'd also check the level of the log messages and set a higher level if possible. Look for this line in conf/logging.properties
java.util.logging.ConsoleHandler.level = ....
Possible levels, in increasing level of frequency are SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST or ALL. I'd try replace ALL, FINEST, FINER, FINE by CONFIG or even INFO. For instance, by setting it to INFO, all SEVERE, WARNING and INFO messages will be logged but not any with a level to the right of that list.
Also another option is set a limit to console handler by adding this line to conf/logging.properties
java.util.logging.ConsoleHandler.limit = 1024000
and rotate catalina.out configuring an automatic task to remove older ones.
if you are linux user to handle this from system is pretty easy you can configure logrotation with logrotate this is very easy
Step : 1 (Create Logrotate file)
root#c2dapp01-usea1e# vim /etc/logrotate.d/tomcat
Step : Add rotation instruction for linux log rotator
/opt/tomcat/latest/logs/catalina.out {
copytruncate
daily
rotate 7
compress
missingok
size 100M
}
Step : 3 Add cron job to run daily in crond.daily or create custom cron (This file is by default there if not then only create)
root#c2dapp01-usea1e:# vim /etc/cron.daily/logrotate
# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
[ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
This script can be run manually.
/usr/sbin/logrotate /etc/logrotate.conf
Most probably the huge size of logs is due to the DEBUG mode setting of log4j. Change this setting to WARN and the size of logging will be reduced.
This is quite common to see catalina.out file expanding.
this could be used to clear the log of catalina.out file without stopping tomcat with the command below.
sudo cat /dev/null > /opt/tomcat/apache-tomcat-9.0.37/logs/catalina.out
To keep catalina.out smaller in size, either one of the following ways can be used:
You could use the above Linux command and add it to a CronScheduler
to run daily/ weekly/ monthly or yearly as preferred.
Use logrotate tool in Linux. It is a log managing command-line tool
in Linux. This can rotate the log files under different conditions.
Particularly, we can rotate log files on a fixed duration or if the
file has grown to a certain size. You can click here for more
info on this.

How to find the WebSphere7 server start/stop history in server

How can I find history of websphere 7 server start or stop from command line or any other logs.
The startServer.log, stopServer.log files contain this information. Additionally, the startup can be seen in the SystemOut.log file as well. Finally, if Verbose GC logging is enabled, the native_stderr.log file will have entries for each JVM restart as well.
These can all be found in {WebSphere Install Dir}/profiles/{Profile Name}/logs/{server name}.

xcodebuild printing too much logs

I'm trying to use 2 commands:
xcodebuild archive -workspace MyProject.xcworkspace -scheme Prod -configuration Prod -archivePath "${WORKSPACE}"/build/MyProject.xcarchive
and
xcodebuild -exportArchive -exportProvisioningProfile "Prov Profile" -exportFormat IPA -exportPath "${WORKSPACE}"/build/MyProject.ipa -archivePath "${WORKSPACE}"/build/MyProject.xcarchive
However, there are way too many lines being logged - around 90k lines or so. normally this isn't a problem, but...
i'm running this on Jenkins, so the log is being logged in JVM memory and i'm getting some weird out of memory exceptions during my jenkins runs (which i think is because somehow with 64 builds, it's showing me 90k lines of logs as opposed to previously 50k lines of logs).
Is there a way to make it so that the logs are silent, until something fails? 90k logs is a LOT of lines to be logging for xcodebuild
I have a hack around this:
have the output be piped to a file on the jenkins server, and tail -f that file to get the logs. you can then even email that tail (if the command had succeeded).
that way, you avoid logging into console, instead you log to file.
something like:
xcodebuild archive -workspace MyProject.xcworkspace -scheme Prod -configuration Prod -archivePath "${WORKSPACE}"/build/MyProject.xcarchive > ~/dzt/tmp/archive_results.txt

How to redirect the stdout and stderr in rolling file with Unix redirection

I have java application which I am running on Unix from the command prompt.
I am redirecting stdout and stderr to console.out and console.err files.
The file size is increasing because a lot of information is being logged.
I want to create a rolling file, when the file size increases above a particular size,
e.g console1.out should get created if console.out size exceeds 500KB.
Currently I am using
java MyAppName > logs/Console.out 2> logs/Console.err &
How can I do this?
Pipe the result to split like this:
java MyAppName | split -b500k - Console.log
This will create a new file every time you go over 500k. See the man-page for split for more details and options.
Or you can use rotatelogs
nohup java MyAppName 2>&1 | rotatelogs -l Console_%Y-%m-%d.log 86400 &
This will create a new file with today's date every day

Categories

Resources