存储应用程序日志一天

时间:2022-10-17 21:39:33

I have an application running in Production. Where we create the logs file. The maximum count of log file is set to 10 and maximum debug write is set to some value such that when a log file becomes of 6MB a new log file is created..

我有一个在Production中运行的应用程序。我们在哪里创建日志文件。日志文件的最大计数设置为10,最大调试写入设置为某个值,以便当日志文件变为6MB时,将创建新的日志文件。

So, we have logs rolling over with file names like :-

所以,我们有日志滚动文件名,如: -

<file_name>.log
<file_name>.log.1
<file_name>.log.2
...
<file_name>.log.10

What my problem is that only logs for 15 minutes can be found in these 10 log files. I know I can update my code base to use DailyRollingFileAppender. But what I'm looking for is a short term solution to store logs for a day such that it can be done without any code changes or minimal code/configuartion changes. For exmaple may be I can acheive this via some cron job or linux command.. etc.

我的问题是在这10个日志文件中只能找到15分钟的日志。我知道我可以更新我的代码库以使用DailyRollingFileAppender。但我正在寻找的是一种短期解决方案,可以存储一天的日志,这样就可以在没有任何代码更改或最小代码/配置更改的情况下完成。对于exmaple可能是我可以通过一些cron作业或linux命令来实现这一点..等等。

Note:- I'm running this application on Linux OS in production.

注意: - 我正在生产Linux操作系统上运行此应用程序。

Any quick help is highly appreciated.

任何快速帮助都非常感谢。

~Thanks

〜谢谢

2 个解决方案

#1


1  

You may do this create a shell script and adding it to cron jobs.

您可以这样做创建一个shell脚本并将其添加到cron作业。

NOW_DATE=$(date +"%m-%d-%Y-%H-%M") 
cd /var/log/OLD_LOGS
mkdir /var/log/OLD_LOGS/$NOW_DATE

cd /var/log/
mv server.log.* /var/log/OLD_LOGS/$NOW_DATE/
mv *.zip /var/log/OLD_LOGS/$NOW_DATE/
cp server.log /var/log/OLD_LOGS/$NOW_DATE/

cd /var/log/OLD_LOGS/$NOW_DATE
x=$(ls -l |wc -l)
if [ $x -le 1 ] then
SUBJECT="There is an issue with generating server log - less number of files"
EMAIL="support@abc.com"
EMAILMESSAGE="/tmp/errormsg.txt"

/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi

cd /var/log/OLD_LOGS/
zip -r $NOW_DATE.zip $NOW_DATE
rm -r -f $NOW_DATE

find /var/log/ -type f -mtime +180 -exec rm {} \;

#2


0  

If the application tries to create .log.11 and if it overwrites the old ones as per the script conditions, there is no possibility of having the logs for a day. What i understand is application logging is much such that all the 10 files have loggings for last 15 minutes and the new lines are again overwritten on them.

如果应用程序尝试创建.log.11,并且如果它根据脚本条件覆盖旧的,则不可能有一天的日志。据我所知,应用程序日志记录非常多,所有10个文件都有最近15分钟的记录,并且新行再次被覆盖。

Application logic should be modified to make sure it captures a day logs. Also, please make sure to zip the files at regular intervals so that you can save some disk space.

应修改应用程序逻辑以确保它捕获日志。另外,请确保定期压缩文件,以便节省一些磁盘空间。

#1


1  

You may do this create a shell script and adding it to cron jobs.

您可以这样做创建一个shell脚本并将其添加到cron作业。

NOW_DATE=$(date +"%m-%d-%Y-%H-%M") 
cd /var/log/OLD_LOGS
mkdir /var/log/OLD_LOGS/$NOW_DATE

cd /var/log/
mv server.log.* /var/log/OLD_LOGS/$NOW_DATE/
mv *.zip /var/log/OLD_LOGS/$NOW_DATE/
cp server.log /var/log/OLD_LOGS/$NOW_DATE/

cd /var/log/OLD_LOGS/$NOW_DATE
x=$(ls -l |wc -l)
if [ $x -le 1 ] then
SUBJECT="There is an issue with generating server log - less number of files"
EMAIL="support@abc.com"
EMAILMESSAGE="/tmp/errormsg.txt"

/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi

cd /var/log/OLD_LOGS/
zip -r $NOW_DATE.zip $NOW_DATE
rm -r -f $NOW_DATE

find /var/log/ -type f -mtime +180 -exec rm {} \;

#2


0  

If the application tries to create .log.11 and if it overwrites the old ones as per the script conditions, there is no possibility of having the logs for a day. What i understand is application logging is much such that all the 10 files have loggings for last 15 minutes and the new lines are again overwritten on them.

如果应用程序尝试创建.log.11,并且如果它根据脚本条件覆盖旧的,则不可能有一天的日志。据我所知,应用程序日志记录非常多,所有10个文件都有最近15分钟的记录,并且新行再次被覆盖。

Application logic should be modified to make sure it captures a day logs. Also, please make sure to zip the files at regular intervals so that you can save some disk space.

应修改应用程序逻辑以确保它捕获日志。另外,请确保定期压缩文件,以便节省一些磁盘空间。