国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Create a Custom Logrotate Configuration File
Test Your Logrotate Configuration
Handle Applications That Don’t Automatically Reopen Logs
Home System Tutorial LINUX How to configure logrotate for custom log files?

How to configure logrotate for custom log files?

Jul 08, 2025 am 12:01 AM

To set up logrotate for custom log files on a Linux server, create a configuration file in /etc/logrotate.d/, define rotation rules, test the setup, and handle apps that don’t reopen logs. 1. Create a config file like /etc/logrotate.d/myapp with rules such as daily, rotate, compress, delaycompress, missingok, notifempty, and create. 2. Test syntax with logrotate -d and force a dry run with logrotate -f. 3. For apps that don’t automatically reopen logs, add a postrotate script using kill -USR1 or systemctl reload to restart the service and ensure logging continues properly.

How to configure logrotate for custom log files?

If you're managing a Linux server and have custom log files from your applications, setting up logrotate is essential. It helps keep logs under control by rotating, compressing, and deleting them automatically. Here’s how to do it right for your own log files.


Create a Custom Logrotate Configuration File

Instead of editing the main /etc/logrotate.conf, it's better to create a separate file in /etc/logrotate.d/. This keeps things clean and easy to manage.

For example, if your app writes logs to /var/log/myapp.log, create a file like this:

sudo nano /etc/logrotate.d/myapp

Inside that file, define the rotation rules. A basic setup might look like:

/var/log/myapp.log {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    create 640 root adm
}

Each line here sets a rule:

  • daily means it rotates every day.
  • rotate 7 keeps seven old logs before deleting older ones.
  • compress compresses rotated logs.
  • delaycompress delays compression until next rotation (good if you need uncompressed logs for analysis shortly after rotation).
  • missingok prevents errors if the log file is missing.
  • notifempty skips rotation if the log is empty.
  • create sets permissions and ownership for the new log file.

Test Your Logrotate Configuration

After setting up or changing the config, test it to make sure there are no syntax errors.

Run:

logrotate -d /etc/logrotate.d/myapp

The -d flag runs it in debug mode, showing what it would do without actually making changes.

If everything looks good, force a dry run with:

logrotate -f /etc/logrotate.d/myapp

This forces a rotation and shows any real-time issues.

Note: If your app doesn't automatically write to a new log file after rotation, you may need to add a postrotate script to reload or restart the service.


Handle Applications That Don’t Automatically Reopen Logs

Some apps don’t notice when their log file has been moved or replaced. In those cases, you can use postrotate to send a signal so they reopen the log.

Update your config like this:

/var/log/myapp.log {
    daily
    rotate 7
    compress
    delaycompress
    notifempty
    create 640 root adm
    postrotate
        /bin/kill -USR1 $(cat /var/run/myapp.pid 2>/dev/null) 2>/dev/null || true
    endscript
}

This sends a USR1 signal to your app, telling it to reopen its log files. Replace /var/run/myapp.pid with the actual path to your app’s PID file.

If your app uses systemd, you might prefer to restart it:

postrotate
    systemctl reload myapp.service
endscript

Make sure to test after adding this part to avoid breaking log writing.


That's basically all you need to set up logrotate for your own log files. It's straightforward once you know which options matter most — and it makes log management way easier in the long run.

The above is the detailed content of How to configure logrotate for custom log files?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

10 Best File Comparison and Difference (Diff) Tools in Linux 10 Best File Comparison and Difference (Diff) Tools in Linux Jun 11, 2025 am 10:26 AM

While writing program files or normal text files, programmers and writers sometimes want to know the difference between two files or two versions of the same file. When you compare two computer files on Linux, the difference between their contents is

How to create a new, empty file from the command line? How to create a new, empty file from the command line? Jun 14, 2025 am 12:18 AM

There are three ways to create empty files in the command line: First, the simplest and safest use of the touch command, which is suitable for debugging scripts or placeholder files; Second, it is quickly created through > redirection but will clear existing content, which is suitable for initializing log files; Third, use echo"> file name to create a file with an empty string, or use echo-n""> file name to avoid line breaks. These three methods have their own applicable scenarios, and choosing the right method can help you complete the task more efficiently.

5 Best Open Source Mathematical Equation Editors for Linux 5 Best Open Source Mathematical Equation Editors for Linux Jun 18, 2025 am 09:28 AM

Are you looking for good software to write mathematical equations? If so, this article provides the top 5 equation editors that you can easily install on your favorite Linux distribution.In addition to being compatible with different types of mathema

dutree - Analyze File System Disk Usage in Linux dutree - Analyze File System Disk Usage in Linux Jun 11, 2025 am 10:33 AM

dutree is a free, open-source, fast command-line tool for analyzing disk usage, written in the Rust programming language. It was created by combining durep (disk usage reporter) and tree (list directory content in tree-like format) command-line tools

How to Install Eclipse IDE in Debian, Ubuntu, and Linux Mint How to Install Eclipse IDE in Debian, Ubuntu, and Linux Mint Jun 14, 2025 am 10:40 AM

Eclipse is a free integrated development environment (IDE) that programmers around the world use to write software, primarily in Java, but also in other major programming languages using Eclipse plugins.The latest release of Eclipse IDE 2023?06 does

15 Useful 'ifconfig' Commands to Configure Network in Linux 15 Useful 'ifconfig' Commands to Configure Network in Linux Jun 11, 2025 am 10:01 AM

ifconfig in short “interface configuration” utility for system/network administration in Unix/Linux operating systems to configure, manage, and query network interface parameters via command-line interface or in a system configuration scripts

SCP Linux Command – Securely Transfer Files in Linux SCP Linux Command – Securely Transfer Files in Linux Jun 20, 2025 am 09:16 AM

Linux administrators should be familiar with the command-line environment. Since GUI (Graphical User Interface) mode in Linux servers is not commonly installed.SSH may be the most popular protocol to enable Linux administrators to manage the servers

24 Hilarious Linux Commands That Will Make You Laugh 24 Hilarious Linux Commands That Will Make You Laugh Jun 14, 2025 am 10:13 AM

Linux has a rich collection of commands, and while many of them are powerful and useful for various tasks, there are also some funny and whimsical commands that you can try out for amusement. 1. sl Command (Steam Locomotive) You might be aware of the

See all articles