• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » How to Manage Logfiles with Logrotate

By Abhishek Ghosh November 12, 2017 5:20 am Updated on November 12, 2017

How to Manage Logfiles with Logrotate

Advertisement

In many guides on this website, we talked about log rotation. Logrotate is Linux utility for automatic rotation, compression, mailing log files etc jobs. Here is how to manage logfiles with logrotate. Many common programs automatically setup Logrotate. Like when we install Apache2, that adds a configuration file used by Logrotate to rotate all apache access and error logs/etc/logrotate.d/apache2. In our other guides, we only mentioned about logrotate script when we built the software from source and/or was sure that the configuration file is not supplied. Logrotate is available on all Linux distributions but default configuration may vary. We are talking in context of Ubuntu 16.04 server. For the others, readers may need checking manual for minimal need of changes. First, we need to check whether logrotate is installed by running :

Vim
1
logrotate --version

If not installed, then we can run the below command(s) to install :

Vim
1
2
3
4
5
6
# Debian/Ubuntu
sudo apt update
sudo apt install logrotate
# Redhat/CentOS
sudo yum update
sudo yum install logrotate

Of course, there is manual of logrorate :

Advertisement

---

Vim
1
man logrotate

 

How to Manage Logfiles with Logrotate

 

/etc/logrotate.conf file contains default settings and includes statement to pull in configuration files from /etc/logrotate.d directory. /etc/logrotate.d/ directory contains the configuration files saved by various applications and utilities. Nothing existing files inside /etc/logrotate.d/ should be altered without knowing about that particular software.

How to Manage Logfiles with Logrotate

For the most daemon processes, logs would be rotated by the root user. logrotate usually invoked from a script in the /etc/cron.daily/ directory.

We can run logrotate as a cronjob to ensure that logs will be rotated as configured. If we configure logrotate to rotate logs every day, but logrotate actually runs every week, the logs will only be rotated every week.

If nothing exist inside /etc/cron.daily/ directory, we need to create a script named /etc/cron.daily/logrotate to do the job :

/etc/cron.daily/logrotate
Vim
1
2
#!/bin/sh
logrotate /etc/logrotate.conf

If I run cat on a server where Apache2 installed :

Vim
1
cat /etc/logrotate.d/apache2

I will get :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/var/log/apache2/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
                if invoke-rc.d apache2 status > /dev/null 2>&1; then
                    invoke-rc.d apache2 reload > /dev/null 2>&1;
                fi;
endscript
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then
run-parts /etc/logrotate.d/httpd-prerotate;
fi;
endscript
}

You need demystification of those phrases.

  • weekly: Rotate logs once per week
  • monthly: Rotate once a month
  • daily: Rotate once a day
  • missingok: Missing OK. If no log files are found, don’t debug or print error.
  • rotate 14: Keep 14 files before deleting old log files
  • compress: Compress (gzip) log files
  • delaycompress: Delays compression until 2nd time rotating.
  • compresscmd: Set which command to used to compress. Defaults to gzip.
  • uncompresscmd: Set the command to use to uncompress. Defaults to gunzip.
  • notifempty: Don’t rotate empty files
  • create 640 root adm: Create new log files with set permissions/owner/group, here user is root and group is adm, permission is 640
  • sharedscripts: Run postrotate script after all logs are rotated
  • postrotate: Scripts to run after rotating is done.
  • size=10M : command sets the minimum size for the rotation to take place to 10M.
  • dateext: This option appends a date instead (logs by default get a number appended to their filename)
  • dateformat: The format of the date appended to the log filename you want.
  • prerotate: Run before log rotating begins

You can run this to test :

Vim
1
2
3
4
# dry run
logrotate -d /etc/logrotate.d/apache2
#
# sudo logrotate /etc/logrotate.d/apache2 --debug

Check what ran by running :

Vim
1
cat /var/lib/logrotate/status

I got a big list like this :

Vim
1
2
3
4
5
6
7
8
9
logrotate state -- version 2
"/var/log/syslog" 2017-11-11-6:25:1
"/var/log/dpkg.log" 2017-11-1-6:25:3
"/var/log/unattended-upgrades/unattended-upgrades.log" 2017-11-1-6:25:3
"/var/log/unattended-upgrades/unattended-upgrades-shutdown.log" 2017-5-26-6:0:0
"/var/log/auth.log" 2017-11-5-6:25:2
"/var/log/apt/term.log" 2017-11-1-6:25:3
...
...

This Article Has Been Shared 427 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to How to Manage Logfiles with Logrotate

  • Ubuntu with GUI on Rackspace Cloud Server as VNC Remote Desktop

    Ubuntu with GUI on Rackspace Cloud Server as VNC Remote Desktop is a guide to install and work on powerful server with up to 48 GB of RAM and GUI from devices.

  • Text Based User Interface (TUI) on SSH Environment

    Here is a Guide on Possibilities of Using Text Based User Interface (TUI) on SSH Environment. Number of Programs Currently is Few in Number.

  • Cloud Computing Jobs is Facing Deficit of Skilled Candidates

    Cloud Computing Jobs is Facing Deficit Skilled Candidates. Some Companies Having Difficulties to Get Candidates with Sufficient Knowledge.

  • Nginx WordPress : Redirect to Geographically Closer Server

    Here is How To Setup Nginx WordPress to Redirect to Geographically Closer Server. This is Called Geo Redundant Setup, Not Very Difficult.

  • How To Configure Nginx Access Log With GeoIP (Ubuntu 16.04)

    Here is How To Configure Nginx Access Log With GeoIP on Ubuntu 16.04. Usage Commands Also Shown. Access Log is Powerful & Configurable Tool.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is Configuration Management February 5, 2023
  • What is ChatGPT? February 3, 2023
  • Zebronics Pixaplay 16 : Entry Level Movie Projector Review February 2, 2023
  • What is Voice User Interface (VUI) January 31, 2023
  • Proxy Server: Design Pattern in Programming January 30, 2023

About This Article

Cite this article as: Abhishek Ghosh, "How to Manage Logfiles with Logrotate," in The Customize Windows, November 12, 2017, February 5, 2023, https://thecustomizewindows.com/2017/11/manage-logfiles-with-logrotate/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT