LoginSignup
2

More than 3 years have passed since last update.

FreeBSDのsyslogでfacilityがdaemonのログを出力する方法

Last updated at Posted at 2019-12-07

FreeBSD12.1でとあるプログラムのログの出力がsyslogのdaemon.infoになっており、
デフォルトではファイルに出力されない設定のようなので、
syslogに設定を追加してfacilityがdaemonのログを出力するようにしてみます

/etc/syslog.conf
# $FreeBSD: releng/12.1/usr.sbin/syslogd/syslog.conf 338146 2018-08-21 17:01:47Z brd $
#
#   Spaces ARE valid field separators in this file. However,
#   other *nix-like systems still insist on using tabs as field
#   separators. If you are sharing this file between systems, you
#   may want to use only tabs as field separators here.
#   Consult the syslog.conf(5) manpage.
*.err;kern.warning;auth.notice;mail.crit        /dev/console
*.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages
security.*                  /var/log/security
auth.info;authpriv.info             /var/log/auth.log
mail.info                   /var/log/maillog
cron.*                      /var/log/cron
!-devd
*.=debug                    /var/log/debug.log
*.emerg                     *
# uncomment this to log all writes to /dev/console to /var/log/console.log
# touch /var/log/console.log and chmod it to mode 600 before it will work
#console.info                   /var/log/console.log
# uncomment this to enable logging of all log messages to /var/log/all.log
# touch /var/log/all.log and chmod it to mode 600 before it will work
#*.*                        /var/log/all.log
# uncomment this to enable logging to a remote loghost named loghost
#*.*                        @loghost
# uncomment these if you're running inn
# news.crit                 /var/log/news/news.crit
# news.err                  /var/log/news/news.err
# news.notice                   /var/log/news/news.notice
# Uncomment this if you wish to see messages produced by devd
# !devd
# *.>=notice                    /var/log/devd.log
!*
include                     /etc/syslog.d
include                     /usr/local/etc/syslog.d

1. syslogの設定追加

/etc/syslog.confを直接編集しても良いですが
別ファイルでincludeされるように出来ているので別ファイルを作成します

/etc/syslog.d/daemon.conf
daemon.*                                          /var/log/daemon.log

2. ログのローテート用のnewsyslogの設定追加

syslogの設定だけで放置しておくとログが無限に溜まり容量を圧迫するため
ログのローテートの設定も行います

/etc/newsyslog.conf.d/daemon.conf
## logfilename          [owner:group]   mode count size when  flags [/pid_file]            [sig_num]
/var/log/daemon.log                     644  7     *    @T00  JBC

3. ファイル作成&syslogdの再起動

syslogdはファイルの作成はしてくれないようなのでファイルを作成したのち再起動します

# touch /var/log/daemon.log
# /etc/rc.d/syslogd restart

4. 確認

# logger -p daemon.info test
# grep test /var/log/daemon.log
Dec  5 10:01:24 hostname root[23146]: test

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2