1<?xml version="1.0" encoding="ISO-8859-1"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!-- 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 This file is generated from xml source: DO NOT EDIT 6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 7 --> 8<title>rotatelogs - Piped logging program to rotate Apache logs - Apache HTTP Server</title> 9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> 10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> 11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" /> 12<script src="/style/scripts/prettify.min.js" type="text/javascript"> 13</script> 14 15<link href="/images/favicon.ico" rel="shortcut icon" /></head> 16<body id="manual-page"><div id="page-header"> 17<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p> 18<p class="apache">Apache HTTP Server Version 2.4</p> 19<img alt="" src="/images/feather.gif" /></div> 20<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 21<div id="path"> 22<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.4</a> > <a href="./">Programs</a></div><div id="page-content"><div id="preamble"><h1>rotatelogs - Piped logging program to rotate Apache logs</h1> 23<div class="toplang"> 24<p><span>Available Languages: </span><a href="/en/programs/rotatelogs.html" title="English"> en </a> | 25<a href="/fr/programs/rotatelogs.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> | 26<a href="/ko/programs/rotatelogs.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 27<a href="/tr/programs/rotatelogs.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 28</div> 29 30 <p><code>rotatelogs</code> is a simple program for use in 31 conjunction with Apache's piped logfile feature. It supports 32 rotation based on a time interval or maximum size of the log.</p> 33</div> 34<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#synopsis">Synopsis</a></li> 35<li><img alt="" src="/images/down.gif" /> <a href="#options">Options</a></li> 36<li><img alt="" src="/images/down.gif" /> <a href="#examples">Examples</a></li> 37<li><img alt="" src="/images/down.gif" /> <a href="#portability">Portability</a></li> 38</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 39<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 40<div class="section"> 41<h2><a name="synopsis" id="synopsis">Synopsis</a></h2> 42 43 <p><code><strong>rotatelogs</strong> 44 [ -<strong>l</strong> ] 45 [ -<strong>L</strong> <var>linkname</var> ] 46 [ -<strong>p</strong> <var>program</var> ] 47 [ -<strong>f</strong> ] 48 [ -<strong>v</strong> ] 49 [ -<strong>e</strong> ] 50 [ -<strong>c</strong> ] 51 [ -<strong>n</strong> <var>number-of-files</var> ] 52 <var>logfile</var> 53 <var>rotationtime</var>|<var>filesize</var>(B|K|M|G) 54 [ <var>offset</var> ]</code></p> 55</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 56<div class="section"> 57<h2><a name="options" id="options">Options</a></h2> 58 59<dl> 60 61<dt><code>-l</code></dt> 62<dd>Causes the use of local time rather than GMT as the base for the 63interval or for <code>strftime(3)</code> formatting with size-based 64rotation.</dd> 65 66<dt><code>-L</code> <var>linkname</var></dt> 67<dd>Causes a hard link to be made from the current logfile 68to the specified link name. This can be used to watch 69the log continuously across rotations using a command like 70<code>tail -F linkname</code>.</dd> 71 72<dt><code>-p</code> <var>program</var></dt> 73 74<dd>If given, <code>rotatelogs</code> will execute the specified 75program every time a new log file is opened. The filename of the 76newly opened file is passed as the first argument to the program. If 77executing after a rotation, the old log file is passed as the second 78argument. <code>rotatelogs</code> does not wait for the specified 79program to terminate before continuing to operate, and will not log 80any error code returned on termination. The spawned program uses the 81same stdin, stdout, and stderr as rotatelogs itself, and also inherits 82the environment.</dd> 83 84<dt><code>-f</code></dt> 85<dd>Causes the logfile to be opened immediately, as soon as 86<code>rotatelogs</code> starts, instead of waiting for the 87first logfile entry to be read (for non-busy sites, there may be 88a substantial delay between when the server is started 89and when the first request is handled, meaning that the 90associated logfile does not "exist" until then, which 91causes problems from some automated logging tools)</dd> 92 93<dt><code>-t</code></dt> 94<dd>Causes the logfile to be truncated instead of rotated. This is 95useful when a log is processed in real time by a command like tail, 96and there is no need for archived data. No suffix will be added to 97the filename, however format strings containing '%' characters 98will be respected. 99</dd> 100 101<dt><code>-v</code></dt> 102<dd>Produce verbose output on STDERR. The output contains 103the result of the configuration parsing, and all file open and 104close actions.</dd> 105 106<dt><code>-e</code></dt> 107<dd>Echo logs through to stdout. Useful when logs need to be further 108processed in real time by a further tool in the chain.</dd> 109 110<dt><code>-c</code></dt> 111<dd>Create log file for each interval, even if empty.</dd> 112 113<dt><code>-n <var>number-of-files</var></code></dt> 114<dd>Use a circular list of filenames without timestamps. 115With -n 3, the series of log files opened would be 116"logfile", "logfile.1", "logfile.2", then overwriting "logfile".</dd> 117 118<dt><code><var>logfile</var></code></dt> 119 120<dd><p>The path plus basename of the logfile. If <var>logfile</var> 121includes any '%' characters, it is treated as a format string for 122<code>strftime(3)</code>. Otherwise, the suffix 123<var>.nnnnnnnnnn</var> is automatically added and is the time in 124seconds (unless the -t option is used). Both formats compute the 125start time from the beginning of the current period. For example, 126if a rotation time of 86400 is specified, the hour, minute, and 127second fields created from the <code>strftime(3)</code> format will 128all be zero, referring to the beginning of the current 24-hour 129period (midnight).</p> 130<p>When using <code>strftime(3)</code> filename formatting, 131be sure the log file format has enough granularity to produce 132a different file name each time the logs are rotated. Otherwise 133rotation will overwrite the same file instead of starting a new 134one. For example, if <var>logfile</var> was 135<code>/var/logs/errorlog.%Y-%m-%d</code> with log rotation at 5 136megabytes, but 5 megabytes was reached twice in the same day, the 137same log file name would be produced and log rotation would keep 138writing to the same file.</p> 139</dd> 140 141<dt><code><var>rotationtime</var></code></dt> 142 143<dd>The time between log file rotations in seconds. The rotation 144occurs at the beginning of this interval. For example, if the 145rotation time is 3600, the log file will be rotated at the beginning 146of every hour; if the rotation time is 86400, the log file will be 147rotated every night at midnight. (If no data is logged during an 148interval, no file will be created.)</dd> 149 150<dt><code><var>filesize</var>(B|K|M|G)</code></dt> 151 152<dd>The maximum file size in followed by exactly one of the letters 153<code>B</code> (Bytes), <code>K</code> (KBytes), <code>M</code> (MBytes) 154or <code>G</code> (GBytes). 155<p> 156When time and size are specified, the size must be given after the time. 157Rotation will occur whenever either time or size limits are reached. 158</p> 159</dd> 160 161<dt><code><var>offset</var></code></dt> 162 163<dd>The number of minutes offset from UTC. If omitted, zero is 164assumed and UTC is used. For example, to use local time in the zone 165UTC -5 hours, specify a value of <code>-300</code> for this argument. 166In most cases, <code>-l</code> should be used instead of specifying 167an offset.</dd> 168 169</dl> 170</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 171<div class="section"> 172<h2><a name="examples" id="examples">Examples</a></h2> 173 174<div class="example"><p><code> 175 CustomLog "|bin/rotatelogs /var/logs/logfile 86400" common 176</code></p></div> 177 178 <p>This creates the files /var/logs/logfile.nnnn where nnnn is 179 the system time at which the log nominally starts (this time 180 will always be a multiple of the rotation time, so you can 181 synchronize cron scripts with it). At the end of each rotation 182 time (here after 24 hours) a new log is started.</p> 183 184<div class="example"><p><code> 185 CustomLog "|bin/rotatelogs -l /var/logs/logfile.%Y.%m.%d 86400" common 186</code></p></div> 187 188 <p>This creates the files /var/logs/logfile.yyyy.mm.dd where 189 yyyy is the year, mm is the month, and dd is the day of the month. 190 Logging will switch to a new file every day at midnight, local time.</p> 191 192<div class="example"><p><code> 193 CustomLog "|bin/rotatelogs /var/logs/logfile 5M" common 194</code></p></div> 195 196 <p>This configuration will rotate the logfile whenever it reaches 197 a size of 5 megabytes.</p> 198 199<div class="example"><p><code> 200 ErrorLog "|bin/rotatelogs /var/logs/errorlog.%Y-%m-%d-%H_%M_%S 5M" 201</code></p></div> 202 <p>This configuration will rotate the error logfile whenever it 203 reaches a size of 5 megabytes, and the suffix to the logfile name 204 will be created of the form 205 <code>errorlog.YYYY-mm-dd-HH_MM_SS</code>.</p> 206 207<div class="example"><p><code> 208 CustomLog "|bin/rotatelogs -t /var/logs/logfile 86400" common 209</code></p></div> 210 211 <p>This creates the file /var/logs/logfile, truncating the file at 212 startup and then truncating the file once per day. It is expected 213 in this scenario that a separate process (such as tail) would 214 process the file in real time.</p> 215 216</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 217<div class="section"> 218<h2><a name="portability" id="portability">Portability</a></h2> 219 220<p>The following logfile format string substitutions should be 221supported by all <code>strftime(3)</code> implementations, see 222the <code>strftime(3)</code> man page for library-specific 223extensions.</p> 224 225<table class="bordered"><tr><td><code>%A</code></td><td>full weekday name (localized)</td></tr> 226<tr class="odd"><td><code>%a</code></td><td>3-character weekday name (localized)</td></tr> 227<tr><td><code>%B</code></td><td>full month name (localized)</td></tr> 228<tr class="odd"><td><code>%b</code></td><td>3-character month name (localized)</td></tr> 229<tr><td><code>%c</code></td><td>date and time (localized)</td></tr> 230<tr class="odd"><td><code>%d</code></td><td>2-digit day of month</td></tr> 231<tr><td><code>%H</code></td><td>2-digit hour (24 hour clock)</td></tr> 232<tr class="odd"><td><code>%I</code></td><td>2-digit hour (12 hour clock)</td></tr> 233<tr><td><code>%j</code></td><td>3-digit day of year</td></tr> 234<tr class="odd"><td><code>%M</code></td><td>2-digit minute</td></tr> 235<tr><td><code>%m</code></td><td>2-digit month</td></tr> 236<tr class="odd"><td><code>%p</code></td><td>am/pm of 12 hour clock (localized)</td></tr> 237<tr><td><code>%S</code></td><td>2-digit second</td></tr> 238<tr class="odd"><td><code>%U</code></td><td>2-digit week of year 239(Sunday first day of week)</td></tr> 240<tr><td><code>%W</code></td><td>2-digit week of year 241(Monday first day of week)</td></tr> 242<tr class="odd"><td><code>%w</code></td><td>1-digit weekday 243(Sunday first day of week)</td></tr> 244<tr><td><code>%X</code></td><td>time (localized)</td></tr> 245<tr class="odd"><td><code>%x</code></td><td>date (localized)</td></tr> 246<tr><td><code>%Y</code></td><td>4-digit year</td></tr> 247<tr class="odd"><td><code>%y</code></td><td>2-digit year</td></tr> 248<tr><td><code>%Z</code></td><td>time zone name</td></tr> 249<tr class="odd"><td><code>%%</code></td><td>literal `%'</td></tr> 250</table> 251 252</div></div> 253<div class="bottomlang"> 254<p><span>Available Languages: </span><a href="/en/programs/rotatelogs.html" title="English"> en </a> | 255<a href="/fr/programs/rotatelogs.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> | 256<a href="/ko/programs/rotatelogs.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 257<a href="/tr/programs/rotatelogs.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 258</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div> 259<script type="text/javascript"><!--//--><![CDATA[//><!-- 260var comments_shortname = 'httpd'; 261var comments_identifier = 'http://httpd.apache.org/docs/2.4/programs/rotatelogs.html'; 262(function(w, d) { 263 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 264 d.write('<div id="comments_thread"><\/div>'); 265 var s = d.createElement('script'); 266 s.type = 'text/javascript'; 267 s.async = true; 268 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 269 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 270 } 271 else { 272 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 273 } 274})(window, document); 275//--><!]]></script></div><div id="footer"> 276<p class="apache">Copyright 2014 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p> 277<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- 278if (typeof(prettyPrint) !== 'undefined') { 279 prettyPrint(); 280} 281//--><!]]></script> 282</body></html>