Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Linux » How To Use Logrotate For Managing Log Files In Ubuntu Linux

How To Use Logrotate For Managing Log Files In Ubuntu Linux

Posted on 26/06/202320/12/2023 Raphael Gab-Momoh By Raphael Gab-Momoh No Comments on How To Use Logrotate For Managing Log Files In Ubuntu Linux
Manage Log-Files-via-Logrotate

This article will show you how To Use Logrotate For Managing Log Files In Ubuntu Linux. To conserve disk space and keep the system operating efficiently, Logrotate is a software program found in Unix/Linux systems that controls the automated rotation, compression, and deletion of log files. It enables administrators to arrange routine log file rotations to prevent accumulating multiple, possibly troublesome log files. Please see Fast user switching: How to create a desktop shortcut in Windows 10 to switch User Accounts, How to change your Windows Computer login Password, How to detect who disabled a user in Active Directory – Best Monitoring Tools and Software, and How to setup WatchGuard Log Server.

For information on which log files need rotation, the frequency of process, and the number of rotated logs to keep, the utility program consults its configuration file (/etc/logrotate.conf or a custom file given on the command line) when it is run.

Then it carries out the necessary operations, like compressing and archiving older log files and creating new ones with a new one. Please also see How to find out who restarted Windows Server, How to Deploy a React Application on Netlify, and Why you should not use Public DNS in Production: Change DNS Server in Windows.

Step 1-Check The Logrotate Version: Use Logrotate For Managing Log Files In Linux

Ubuntu comes with the software program pre-installed. The instructions below will update your package list and get the package if you need to install it, though:

sudo apt update
sudo apt install logrotate
install-logratate-after-upgrading-system
install logrotate

To confirm the installation of the system utility, ask for Logrotate’s version information. If you are using a non-Ubuntu server, you can confirm installation using the command below:

logrotate --version
logrotate-version
checking the version of the log rotate

Some of the configuration options covered in this tutorial may not work properly if you install the system utility and the version number is significantly different. Read the manual (man) page of the version of utility program you are using to find the documentation

Step 2- Take a closer look at the Logrotate configuration: Use Logrotate For Managing Log Files In Linux

Typically, you can find information about Logrotate’s setup in two locations on Ubuntu:

  1. /etc/logrotate.conf: The file /etc/logrotate.conf, which also contains specific default settings set up the rotation of a few logs not owned by any system packages. You can retrieve the configuration from any file in the /etc/logrotate.d directory using the include statement.
  2. /etc/logrotate.d/ : Any programs you install requiring log rotation assistance will place their utility settings in /etc/logrotate.d/. Additionally, for essential system tools like apt, dpkg, rsyslog, and others, there should already be files on a typical installation.

Let’s see what’s inside the /etc/logrotate.d.cat configuration file for a particular file for the apt package utility using the command:

cat /etc/logrotate.d/apt
examining-the-file
content of Logrotate configuration file

This file provides configuration blocks for the term.log and history.log log files located in the /var/log/apt directory. Meanwhile, both of them have the same choices. For settings not provided in these configuration sections, the system will use the default values or those specified in /etc/logrotate.conf.

Furthermore, any setting in a system utility file overrides the default values for logrotate, set in /etc/logrotate.conf. As shown from the screenshot above, the following parameters are configured for apt logs:

Rotate 12: preserve twelve previous log files. The rotate 4 default is replaced with this.
Compress: Compress rotated files. By default, this utilizes gzip, which produces files with a.gz extension. In addition, the compressed option allows you to modify the compression command
missingOk: Don’t write an error message if the log file is missing.
notifempty: If the log file is empty, do not rotate it.

Step 3- Creating an Example Configuration: Use Logrotate to manage Log File

For a hypothetical web server that stores an access.log and an error.log into /var/log/my-app/. It operates under the www-data group and user.

Open a new file in the /etc/logrotate.d directory using vim or your preferred editor to add a setting for the my-app log files using the command below:

sudo vim /etc/logrotate.d/my-app

Include the lines below in your new configuration file:

/var/log/my-app/*.log {
	daily
	missingok
	rotate 14
	compress
	notifempty
	create 0640 www-data www-data
	sharedscripts
	postrotate
		systemctl reload my-app
	endscript
}

these are a few of the new configuration instructions in this file:

To save and quit vim, Hit the escape button on your keyboard and type :wq.

type-colon-wq-to-quit-vim
Hit the escape button, colon wq to quit Vim

You can test the config file by doing a dry run:

sudo logrotate /etc/logrotate.conf --debug

This command activates debug mode, invokes logrotate, and specifies the standard configuration file.

testing-logrotate
testing logrotate

Summary

The article explains how Logrotate helps manage log files in Linux by automating compression, archiving, and deletion based on predefined criteria.

It offers a step-by-step guide on installation, configuration, and customization options. Logrotate proves valuable for Linux system administrators handling log file management.

I hope you found this blog post helpful for using Logrotate to manage Log Files In Ubuntu Linux. Please let me know in the comment section if you have any questions.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
Linux Tags:Ubunt 20.04 LTS, Ubuntu

Post navigation

Previous Post: Create App Service Resource with Azure CLI
Next Post: How to Setup GitLab Runner on WSL

Related Posts

  • Add User to Sudoers
    Add a User to the Sudoers List in Linux Linux
  • finalelastic
    How to Install and Configure Elasticsearch on Linux  Linux
  • Convert PEM to PPK 1
    Convert a PEM Key to a PPK Key on a Linux and Windows AWS/Azure/OpenShift
  • apache ubuntu 20 04
    How to Install Apache HTTP Server on Ubuntu 20.04 LTS Linux
  • image 129
    How to deploy Ansible AWX on centos 8 Linux
  • screenshot 2020 04 23 at 00.30.09
    How to mount a USB Drive in Linux Linux

More Related Articles

Add User to Sudoers Add a User to the Sudoers List in Linux Linux
finalelastic How to Install and Configure Elasticsearch on Linux  Linux
Convert PEM to PPK 1 Convert a PEM Key to a PPK Key on a Linux and Windows AWS/Azure/OpenShift
apache ubuntu 20 04 How to Install Apache HTTP Server on Ubuntu 20.04 LTS Linux
image 129 How to deploy Ansible AWX on centos 8 Linux
screenshot 2020 04 23 at 00.30.09 How to mount a USB Drive in Linux Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

Veeam Vanguard

  • Windows Defender exclusion
    Mitigate Veeam Threat Hunter Service Scanning Interference Windows Server
  • MBAM
    Fix MBAM Client Deployment is only supported on MBAM 2.5 SP1 Windows
  • microsoft authenticator 1280x720 1
    How to setup Microsoft Authenticator Password Manager
  • Featured image Periodic scanning
    How to enable or disable Windows Defender Antivirus Scanning periodically on Windows via Windows Settings Security | Vulnerability Scans and Assessment
  • Feature image  Error Code 0xC1900101 – 0x30018
    How to Fix Windows Update Error Code 0xC1900101 – 0x30018 Windows
  • Netstat
    Network statistics: How to save netstat command output to a text Web Server
  • Error during connect in the default daemon configuration on Windows
    Preparation failed: The docker client must be run with elevated privileges Version Control System
  • Comprehensive Guide to Passkeys on Windows Devices
    Comprehensive Guide to Passkeys on Windows Devices Windows

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,808 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.