As you may already know, FreeBSD differentiates system applications from those installed by third parties, so services such as named , for example, do not have their configuration in /etc directly as with GNU/Linux, but are moved to /usr/local/etc , which from the Unix perspective, makes much more sense. But we won’t go into this discussion now.

What we are interested in is to be able to rotate the logs , as happens with for example those generated by maillog. And for this FreeBSD has a utility called newsyslog. You can consult the manual here.

Its configuration is found in /etc/newsyslog.conf , now this is a system utility, and it looks like this:

root@fbsdsrv01:~ # cat /etc/newsyslog.conf
# configuration file for newsyslog
# $FreeBSD$
#
# Entries which do not specify the '/pid_file' field will cause the
# syslogd process to be signalled when that log file is rotated.  This
# action is only appropriate for log files which are written to by the
# syslogd process (ie, files listed in /etc/syslog.conf).  If there
# is no process which needs to be signalled when a given log file is
# rotated, then the entry for that file should include the 'N' flag.
#
# Note: some sites will want to select more restrictive protections than the
# defaults.  In particular, it may be desirable to switch many of the 644
# entries to 640 or 600.  For example, some sites will consider the
# contents of maillog, messages, and lpd-errs to be confidential.  In the
# future, these defaults may change to more conservative ones.
#
# logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
/var/log/all.log   600  7  * @T00  J
/var/log/auth.log   600  7     1000 @0101T JC
/var/log/console.log   600  5  1000 *     J
/var/log/cron    600  3  1000 *     JC
/var/log/daily.log   640  7  * @T00  JN
/var/log/debug.log   600  7     1000 *     JC
/var/log/init.log   644  3  1000 *     J
/var/log/kerberos.log   600  7  1000 *     J
/var/log/maillog   640  7  * @T00  JC
/var/log/messages   644  5  1000 @0101T JC
/var/log/monthly.log   640  12  * $M1D0 JN
/var/log/devd.log   644  3  1000 *     JC
/var/log/security   600  10  1000 *     JC
/var/log/utx.log   644  3  * @01T05 B
/var/log/weekly.log   640  5  * $W6D0 JN
/var/log/daemon.log   644  5  1000 @0101T JC

<include> /etc/newsyslog.conf.d/[!.]*.conf
<include> /usr/local/etc/newsyslog.conf.d/[!.]*.conf
root@fbsdsrv01:~ #

That we can easily interpret. Perhaps the most cumbersome column is the when column, but a glance at the manual will quickly clarify it for us. Now for example we could add a line like:

/var/log/named.log bind:bind 644  7  * @T00  J   /var/run/named/pid

Inside /usr/local/etc/newsyslog.conf.d/named.conf , this time in the non-base application path, and in which we will specify that we want the named service to rotate its log daily, regardless of its size, and up to a maximum of 7.

Let’s remember to restart this newsyslog daemon just in case, although I think it is not strictly necessary.

root@fbsdsrv01:~ # service newsyslog restart
Creating and/or trimming log files.
root@fbsdsrv01:~ #