Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use cronolog to cut server log files in Linux

Shulou Source: shulou.com Published: 2022-06-01 22:18:55 09月12日 Update

This article introduces you how to use cronolog in Linux to cut server log files, the content is very detailed, interested friends can refer to, I hope to help you.

Download (latest version)

The code is as follows:

# wget http://cronolog.org/download/cronolog-1.6.2.tar.gz

2. Decompression

The code is as follows:

# tar zxvf cronolog-1.6.2.tar.gz

3. Enter the directory where cronolog installation files are located

The code is as follows:

# cd cronolog-1.6.2

4. Operation and installation

The code is as follows:

# ./ configure

# make

# make install

5. Check the directory where cronolog is installed (verify that the installation is successful)

The code is as follows:

# which cronolog

Usually displayed as: /usr/local/sbin/cronolog

The installation process is complete. The following is the log format configuration:

1. Virtual host configuration file httpd-vhosts.conf

Modify the Web log setting CustomLog to the following format

The code is as follows:

CustomLog "|/usr/local/sbin/cronolog /www/logs/example_%Y%m%d.log" combined

Of course, the error log setting ErrorLog can also be divided by cronolog, set to

The code is as follows:

ErrorLog "|/usr/local/sbin/cronolog /www/logs/error_%Y%m%d.log"

2, if there is only one site on the server (of course, this situation is relatively rare), directly according to the above format to modify the httpd.conf file log settings.

Description:

The green part is the location of cronolog after installation. The location may not be exactly the same for different system versions. The location viewed by which command shall prevail.

The blue part is the location of the set log file, which can be modified as needed;

The red part is the set log file identification character, which can be modified as needed;

%Y%m%d is the log file partition method, in the example, it is "year, day", or it can be modified to your own needs.

Modify the httpd.conf file:

This file is located in/etc/httpd/conf/httpd.conf on my computer. Different servers should be different.

Add at the end

The code is as follows:

# ServerAdmin webmaster@dummy-host.example.com

# DocumentRoot /www/docs/dummy-host.example.com

# ServerName dummy-host.example.com

ErrorLog /data/logs/apache/webapps.wps.cn-error_log

CustomLog "|/usr/local/sbin/cronolog /data/logs/apache/%Y%m%d/access_log.% H" combined

#This ensures that a folder every day generates a log every hour under the folder

#CustomLog "|/usr/local/sbin/cronolog /data/logs/apache/%Y%m%%Hdaccess_log" combined

Go to/etc/init.d/httpd configtest to verify that your configuration file is correct

Go to/etc/init.d/httpd restart Restart the apache server (different systems should be different to find)

For Tomcat

the first step

will

The code is as follows:

if [ -z "$CATALINA_OUT" ] ; then

CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out

fi

modified to

The code is as follows:

if [ -z "$CATALINA_OUT" ] ; then

CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out.% Y-%m-%d

fi

the second step

will

The code is as follows:

touch "$CATALINA_OUT"

changed to

The code is as follows:

#touch "$CATALINA_OUT"

the third step

will

The code is as follows:

org.apache.catalina.startup.Bootstrap "$@" start \

>> "$CATALINA_OUT" 2>&1 &

modified to

The code is as follows:

org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \

| /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &

restart the Tomcat

The code is as follows:

service tomcat restart

About how to use cronolog in Linux to cut server log files to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Code file log server service location part different format configuration content situation location folder more version directory system post help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information Huawei MariaDB vpn