title: Use newsyslog to rotate log files, but only if they have a certain size
body: <p>I'm on OS X 10.9.4 and trying to use <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man8/newsyslog.8.html" rel="nofollow">newsyslog</a> to rotate my app development log files.</p>
  
  <p>More specifically, I want to rotate the files daily but only if they are not empty (newsyslog writes one or two lines to every logfile it rotates, so let's say I only want to rotate logs that are at least 1kb).</p>
  
  <p>I created a file <code>/etc/newsyslog.d/code.conf</code>:</p>
  
  <pre><code># logfilename                     [owner:group]   mode  count  size  when   flags [/pid_file] [sig_num]
  /Users/manuel/code/**/log/*.log   manuel:staff    644   7      1     $D0    GN
  </code></pre>
  
  <p>The way I understand the <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man5/newsyslog.conf.5.html" rel="nofollow">man page for the configuration file</a> is that <code>size</code> and <code>when</code> conditions should work in combination, so logfiles should be rotated every night at midnight <strong>only if</strong> they are 1kb or larger.</p>
  
  <p>Unfortunately this is not what happens. The log files are rotated every night, no matter if they only the rotation message from newsyslog or anything else:</p>
  
  <pre><code>~/code/myapp/log (master) $ ls
  total 32
  drwxr-xr-x   6 manuel  staff   204B Aug  8 00:17 .
  drwxr-xr-x  22 manuel  staff   748B Jul 25 14:56 ..
  -rw-r--r--   1 manuel  staff    64B Aug  8 00:17 development.log
  -rw-r--r--   1 manuel  staff   153B Aug  8 00:17 development.log.0
  
  ~/code/myapp/log (master) $ cat development.log
  Aug  8 00:17:41 localhost newsyslog[81858]: logfile turned over
  
  ~/code/myapp/log (master) $ cat development.log.0 
  Aug  7 00:45:17 Manuels-MacBook-Pro newsyslog[34434]: logfile turned over due to size&gt;1K
  Aug  8 00:17:41 localhost newsyslog[81858]: logfile turned over
  </code></pre>
  
  <p>Any tips on how to get this working would be appreciated!</p>