Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security, Veeam & DevOps

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form

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
  1. Home
  2. Linux
  3. 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

  • goland
    How to install Golang on a Linux System Linux
  • elasticsearch error feature
    Elasticsearch: How to stop systemd service start operation from timing out Linux
  • feature image sublime text 4
    How to install Sublime Text 4 on Ubuntu Linux
  • Errno 256 No more mirrors to try 1
    How to solve Errno 256 Linux
  • Generate SSH Keys
    Associate SSH Public key with Azure Linux VM AWS/Azure/OpenShift
  • feature photo quit vim
    How to Exit Linux Vim or Vi Editor Linux

More Related Articles

goland How to install Golang on a Linux System Linux
elasticsearch error feature Elasticsearch: How to stop systemd service start operation from timing out Linux
feature image sublime text 4 How to install Sublime Text 4 on Ubuntu Linux
Errno 256 No more mirrors to try 1 How to solve Errno 256 Linux
Generate SSH Keys Associate SSH Public key with Azure Linux VM AWS/Azure/OpenShift
feature photo quit vim How to Exit Linux Vim or Vi Editor 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

  • unnamed 2
    How to create a contact in Active Directory Windows Server
  • windows update 03
    Fix Windows cannot check for updates in Windows 8, 7, and 10 Windows
  • HighA
    Virtual Machine Scale Set: Demonstrating High Availability in Azure AWS/Azure/OpenShift
  • Schedule and join Teams Meeting
    How to schedule and join meetings with Microsoft Teams JIRA|Confluence|Apps
  • ChatGPT on Linux
    Set Up and Use ChatGPT in Linux Terminal Linux
  • Dockerxx1
    How to install and uninstall Docker Desktop on Windows 10 and Windows Server Containers
  • Featured image BSOD
    How to troubleshoot and fix Windows 11 blue screen Windows
  • powershell commands lede 1024x276 1
    PowerShell Remoting: Guide to Windows Management Instrumentation Scripts

Subscribe to Blog via Email

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

Join 1,786 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

Active Directory 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.