RaspberryPi ログ

ログファイル

ログファイルを参照して動作するプログラムを作りたい。 システム系のログは、/var/log/ 内にファイルが保存されている。 ↓の感じ

root@raspberrypi:/var/log# ls -l
合計 320
-rw-r--r-- 1 root root      0 11月 29 11:37 alternatives.log
drwxr-xr-x 2 root root   4096  2月 22 19:27 apt
-rw-r----- 1 root adm    7932  2月 23 09:17 auth.log
-rw-r--r-- 1 root root   4750  2月 22 19:35 boot.log
-rw-r--r-- 1 root root      0 11月 29 11:37 bootstrap.log
-rw------- 1 root utmp    384 11月 29 11:37 btmp
-rw-r----- 1 root adm   52276  2月 23 09:36 daemon.log
-rw-r----- 1 root adm    2494  2月 22 19:35 debug
-rw-r--r-- 1 root root   3440  2月 22 19:27 dpkg.log
-rw-r--r-- 1 root root      0 11月 29 11:37 faillog
-rw-r----- 1 root adm   51675  2月 22 19:35 kern.log
-rw-rw-r-- 1 root utmp 292292  2月 23 08:51 lastlog
-rw-r----- 1 root adm   49543  2月 22 19:35 messages
drwxr-x--- 2 root adm    4096 11月 21 07:24 samba
-rw-r----- 1 root adm  106773  2月 23 09:36 syslog
-rw-r----- 1 root adm     600  2月 22 19:35 user.log
-rw-rw-r-- 1 root utmp   5760  2月 23 08:51 wtmp

syslogかmessageが主。 今回は、hostapdのログが欲しかったのでsyslog。

なんですが、参照するにしてもでかくなりすぎると処理時間がとんでもないことにならない?

調べると、保存期間は /etc/logrotate.conf や /etc/logrotate.d/rsyslog 等で設定できる。 ↓設定ファイル内

root@raspberrypi:/var/log# cat /etc/logrotate.d/rsyslog
/var/log/syslog
{
        rotate 7
        daily
        missingok
        notifempty
        delaycompress
        compress
        postrotate
                invoke-rc.d rsyslog rotate > /dev/null
        endscript
}

/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
        rotate 4
        weekly
        missingok
        notifempty
        compress
        delaycompress
        sharedscripts
        postrotate
                invoke-rc.d rsyslog rotate > /dev/null
        endscript
}

の中の rotate 7 が7回分、 daily が一日分なので、 1日ごとにファイルを作成して、7日分保管する。 つまり一週間、ログを保存しますよ、と。 一日のログなら、とんでもなくでかくなることはないか。 良し。