Operating System - Linux
1751797 Members
5405 Online
108781 Solutions
New Discussion юеВ

Re: Manage the logs of an application.

 
SOLVED
Go to solution
Alpha977
Valued Contributor

Manage the logs of an application.

Hello to all!

An application on my server generate log files with a specific dimension, ex:

application_log1.txt 10Mb
application_log2.txt 10Mb
application_log3.txt 9Mb

When the dimension reach the limit it overwrite the files.

Now i need to tar the log, and i must to create a script to zip the log when reach the limit, ordered by date.

How i can do this?

Thank you!

Points for all reply.
6 REPLIES 6
Ivan Krastev
Honored Contributor

Re: Manage the logs of an application.

Write a script to check every 5 min if size of logs is reached 10Mb and after that perform actions: tar, rename, zip

Another options is to use logrotate mechanism: see how other logs are processed in /etc/logrotate.d/*

regards,
ivan
Alpha977
Valued Contributor

Re: Manage the logs of an application.

Thank you for your advice!

Can you give me an example of script?

Thank you!
Ivan Ferreira
Honored Contributor

Re: Manage the logs of an application.

You may need to do a command like this in your "rotation script" if you don't use logrotate:

tar zcvf application_log-$(date +%m-%d-%Y).tgz application_log*
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Alpha977
Valued Contributor

Re: Manage the logs of an application.

Thank you Ivan.

I'm going to see how logrotate work.

How do you use logrotate in this case?

Thank you
Court Campbell
Honored Contributor
Solution

Re: Manage the logs of an application.

cd /etc/logrotate.d

look at the files in that directory. usually you create a file named after the service/daemon that is creating the log files. Just mimic one of the files in that directory. man logrotate tells more about the options that can be put in the file. here is a sample:

/var/log/application_log?.txt {
rotate 5
weekly
size=10M
compress
postrotate /sbin/killall -HUP
endscript
}

Notice the ? above. You can use globs in choosing the file. Otherwise you create a list like this:

/var/log/application_log1.txt /var/log/application_log2.txt /var/log/application_log3.txt{
rotate 5
weekly
size=10M
compress
postrotate /sbin/killall -HUP
endscript
}
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Alpha977
Valued Contributor

Re: Manage the logs of an application.

Thank to all for all reply!

This week i will try this last solution.

Bye!