{"id":1256,"date":"2016-08-24T05:03:07","date_gmt":"2016-08-24T13:03:07","guid":{"rendered":"https:\/\/www.cloudinsidr.com\/content\/?p=1256"},"modified":"2016-08-24T05:03:52","modified_gmt":"2016-08-24T13:03:52","slug":"how-to-get-a-grip-on-your-log-files-growing-outta-control-set-up-and-force-logrotate","status":"publish","type":"post","link":"https:\/\/www.cloudinsidr.com\/content\/how-to-get-a-grip-on-your-log-files-growing-outta-control-set-up-and-force-logrotate\/","title":{"rendered":"How to get a grip on your log files growing outta control: set up and force logrotate"},"content":{"rendered":"<p>Logs that grow in size uncontrollably can cause unintended consequences. If you keep ignoring the situation, it will only get worse until you run our of disc space, the system starts being unresponsive or processes begin to crash.<\/p>\n<p><!--more--><\/p>\n<h4>Check what&#8217;s up<\/h4>\n<p>To verify how large your logs are, use (on Linux):<\/p>\n<pre>ls -lSh\u00a0\/var\/log<\/pre>\n<p>It will show long output (-l) including log file sizes (-S) in human readable form (-h). In order to have a peek at the most recent contents without the need to open the file and scroll through a seemingly infinite number of meaningless pages, use the command tail, for example:<\/p>\n<pre>tail maillog<\/pre>\n<p>If you want it to keep scrolling while you sit back and watch, use:<\/p>\n<pre>tail maillog &amp;<\/pre>\n<p>Should you run across a log file that you cannot reasonably handle and no longer need, don&#8217;t try to delete and recreate it; the affected process may crash. Instead, empty the file using:<\/p>\n<pre>&gt; log<\/pre>\n<h4>Set up logrotate<\/h4>\n<p>Some processes may not rotate their logs automatically. The popular open source mail delivery agent dovecot is a good example: it will keep writing to the same log file until the cows come home. On some systems, you may experience such a heavy activity (or demand such a detailed log output), that the resulting log file sizes will be entirely out of the ballpark.\u00a0In both cases, the nifty log management utility logrotate can lend you a hand.<\/p>\n<p>The logrotate utility looks for\u00a0its main configuration file at<\/p>\n<pre>\/etc\/logrotate.conf<\/pre>\n<p>Here, you will find settings that define how often log files will be rotated, how many backlogs will be kept, and where.<\/p>\n<p>In order to configure logrotate for a process, add a directive\u00a0such as this one to the main configuration file of logrotate at \/etc\/logrotate.conf (this is an example for dovecot):<\/p>\n<pre>\/var\/log\/dovecot.log {\r\n weekly\r\n minsize 1M\r\n create 0664 vmail vmail\r\n rotate 6\r\n}<\/pre>\n<p>Dovecot&#8217;s default log\u00a0file located at \/var\/log\/dovecot.log will be rotated weekly unless it is smaller than 1MB; the user is vmail; the group is vmail. The system will maintain six of these backlog files.<\/p>\n<h4>Force logrotate (once)<\/h4>\n<p>In order to force logrotate on the command line:<\/p>\n<pre>logrotate --force \/etc\/logrotate.conf<\/pre>\n<p>Example output of the ls command before:<\/p>\n<pre>-rw-r--r-- 1 root root 0 May 20 2014 dovecot\r\n-rw-r--r-- 1 vmail vmail 42805 May 15 2014 dovecot-info.log\r\n-rw-r--r-- 1 vmail vmail 120402253 Aug 20 15:12 dovecot.log<\/pre>\n<p>Example output of the ls command after:<\/p>\n<pre>-rw-r--r-- 1 root root 0 May 20 2014 dovecot\r\n-rw-r--r-- 1 vmail vmail 42805 May 15 2014 dovecot-info.log\r\n-rw-rw-r-- 1 vmail vmail 0 Aug 20 15:28 dovecot.log\r\n-rw-r--r-- 1 vmail vmail 120412659 Aug 20 15:29 dovecot.log-20160820<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Logs that grow in size uncontrollably can cause unintended consequences. If you keep ignoring the situation, it will only get worse until you run our of disc space, the system starts being unresponsive or processes begin to crash.<\/p>\n","protected":false},"author":1,"featured_media":76,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[16,155,143,2,6],"tags":[151,15],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to get a grip on your log files growing outta control: set up and force logrotate - CloudInsidr<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cloudinsidr.com\/content\/how-to-get-a-grip-on-your-log-files-growing-outta-control-set-up-and-force-logrotate\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get a grip on your log files growing outta control: set up and force logrotate - CloudInsidr\" \/>\n<meta property=\"og:description\" content=\"Logs that grow in size uncontrollably can cause unintended consequences. If you keep ignoring the situation, it will only get worse until you run our of disc space, the system starts being unresponsive or processes begin to crash.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudinsidr.com\/content\/how-to-get-a-grip-on-your-log-files-growing-outta-control-set-up-and-force-logrotate\/\" \/>\n<meta property=\"og:site_name\" content=\"CloudInsidr\" \/>\n<meta property=\"article:published_time\" content=\"2016-08-24T13:03:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-08-24T13:03:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.cloudinsidr.com\/content\/wp-content\/uploads\/2015\/11\/cloudinsidr_logo_900px-wide.png\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"326\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#website\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/\",\"name\":\"CloudInsidr\",\"description\":\"Cyber security, infotech\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.cloudinsidr.com\/content\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-get-a-grip-on-your-log-files-growing-outta-control-set-up-and-force-logrotate\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/wp-content\/uploads\/2015\/11\/cloudinsidr_logo_900px-wide.png\",\"width\":900,\"height\":326,\"caption\":\"cloudinsidr.com logo (900px wide)\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-get-a-grip-on-your-log-files-growing-outta-control-set-up-and-force-logrotate\/#webpage\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-get-a-grip-on-your-log-files-growing-outta-control-set-up-and-force-logrotate\/\",\"name\":\"How to get a grip on your log files growing outta control: set up and force logrotate - CloudInsidr\",\"isPartOf\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-get-a-grip-on-your-log-files-growing-outta-control-set-up-and-force-logrotate\/#primaryimage\"},\"datePublished\":\"2016-08-24T13:03:07+00:00\",\"dateModified\":\"2016-08-24T13:03:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#\/schema\/person\/dd6ee9cb21cf05763fd7cff3d6f11b2b\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.cloudinsidr.com\/content\/how-to-get-a-grip-on-your-log-files-growing-outta-control-set-up-and-force-logrotate\/\"]}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#\/schema\/person\/dd6ee9cb21cf05763fd7cff3d6f11b2b\",\"name\":\"Cloud Insidr\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8b2fa1415b3d573b97d818b8f8f83b7c?s=96&d=mm&r=g\",\"caption\":\"Cloud Insidr\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/1256"}],"collection":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/comments?post=1256"}],"version-history":[{"count":10,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/1256\/revisions"}],"predecessor-version":[{"id":1266,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/1256\/revisions\/1266"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/media\/76"}],"wp:attachment":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/media?parent=1256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/categories?post=1256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/tags?post=1256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}