LinkIt Smart 7688を使ってみる

syslog機能

LinkIt(OpenWrt)にもsyslog機能が有りますが、今までのLinuxとはかなり違っています。
/var/logにはそれらしいファイルが有りませんが、dmesgコマンドは動きます。
root@mylinkit:~# ls -l /var/log
-rw-r--r--    1 root     root             0 Jan  7 10:29 lastlog
-rw-r--r--    1 root     root             0 Jan  7 10:29 log.nmbd
-rw-r--r--    1 root     root             0 Jan  7 10:29 log.smbd
-rw-r--r--    1 root     root             0 Jan  7 10:29 wtmp

root@mylinkit:~# ls -l /bin/dmesg
lrwxrwxrwx    1 root     root             7 Sep 27  2016 /bin/dmesg -> busybox

root@mylinkit:~# dmesg | tail
[   24.520000] br-lan: port 1(eth0) entered forwarding state
[   25.310000] efuse_probe: efuse = 10000012
[   25.500000] tssi_0_target_pwr_g_band = 35
[   25.510000] tssi_1_target_pwr_g_band = 35
[   26.520000] br-lan: port 1(eth0) entered forwarding state
[   32.960000] <==== rt28xx_init, Status=0
[   35.320000] device ra0 entered promiscuous mode
[   35.320000] br-lan: port 2(ra0) entered forwarding state
[   35.330000] br-lan: port 2(ra0) entered forwarding state
[   37.330000] br-lan: port 2(ra0) entered forwarding state

こ ちらにログのクリアーに関する質問が有りますが、

Because the contents of the System log are not in a file but in  memory buffer internal to the log daemon.
Logread accesses that buffer and outputs the contents  in cleartext.

だそうです。



loggerコマンドを使って好きなログを書き込むことができます。
root@mylinkit:~# logger --help
BusyBox v1.23.2 (2016-09-27 07:54:34 CEST) multi-call binary.

Usage: logger [OPTIONS] [MESSAGE]

Write MESSAGE (or stdin) to syslog

        -s      Log to stderr as well as the system log
        -t TAG  Log using the specified tag (defaults to user name)
        -p PRIO Priority (numeric or facility.level pair)

ログに書き込まれている内容はlogreadコマンドを使って見ることができます。
root@mylinkit:/tmp/log# logread --help
logread: invalid option -- -
Usage: logread [options]
Options:
    -s <path>           Path to ubus socket
    -l  <count>         Got only the last 'count' messages
    -e  <pattern>       Filter messages with a regexp
    -r  <server> <port> Stream message to a server
    -F  <file>          Log file
    -S  <bytes>         Log size
    -p  <file>          PID file
    -h  <hostname>      Add hostname to the message
    -P  <prefix>        Prefix custom text to streamed messages
    -f                  Follow log messages
    -u                  Use UDP as the protocol
    -0                  Use \0 instead of \n as trailer when using TCP

試しにloggerコマンドでログを書いてみました。
root@mylinkit:~# logger -p syslog.info -t TEST "loggingTEST"

logreadでログを読むと、このように表示されます。
root@mylinkit:~# logread -l 10
Mon Jan  7 22:38:08 2019 daemon.notice netifd: wan (1748): Lease of 192.168.10.187 obtained, lease time 86400
Tue Jan  8 10:38:09 2019 daemon.notice netifd: wan (1748): Sending renew...
Tue Jan  8 10:38:09 2019 daemon.notice netifd: wan (1748): Lease of 192.168.10.187 obtained, lease time 86400
Tue Jan  8 11:50:19 2019 authpriv.info dropbear[1965]: Child connection from fe80::d5ac:28df:85c5:f933%apcli0:57381
Tue Jan  8 11:50:31 2019 authpriv.notice dropbear[1965]: Password auth succeeded for 'root' from fe80::d5ac:28df:85c5:f933%apcli0:57381
Tue Jan  8 11:58:26 2019 authpriv.info dropbear[2139]: Child connection from fe80::d5ac:28df:85c5:f933%apcli0:57535
Tue Jan  8 11:58:31 2019 authpriv.notice dropbear[2139]: Password auth succeeded for 'root' from fe80::d5ac:28df:85c5:f933%apcli0:57535
Tue Jan  8 12:20:16 2019 syslog.info TEST: loggingTEST
Tue Jan  8 12:23:47 2019 syslog.info TEST: loggingTEST
Tue Jan  8 12:33:15 2019 syslog.info TEST: loggingTEST

続く....