How to write syslog/logd to external drive

Hi,

I want to write the syslog to a flash drive in addition to the standard ring buffer; so within /etc/config/system, I added the line:

log_file option '/mnt/log/system.log'

However, upon rebooting the router, I don't see the logfile created.

I did use the luci "app" (from the block-mount package) to auto-mount the flash drive at /mnt/log and all my other ulogd logs are working fine using that directory, so I don't believe it is a mounting issue.

Does it have something to do with the logd vs mounting startup order? I'm not that familiar with how the files in /etc/rc.d work.

Thanks.

If it is not a mistake when creating the topic, the correct syntax is

option log_file '/mnt/log/system.log'
1 Like

Actually; I mistyped that last night; was tired.

The syntax is correct; I do have it as:

option log_file “/mnt/log/system.log”

So it has to be something else.

Please post the output of the following commands:

uci export system; ll /mnt/; ll /mnt/log/; \
/etc/init.d/system restart; /etc/init.d/log restart; \
ll /mnt/log
1 Like

"uci export system" outputs:

package system

config system
        option ttylogin '1'
        option log_size '64'
        option log_file '/mnt/log/openwrt.log'
        option urandom_seed '0'
        option log_proto 'udp'
        option conloglevel '8'
        option cronloglevel '5'
        option hostname 'LJNetCBP'
        option zonename 'America/Chicago'
        option timezone 'CST6CDT,M3.2.0,M11.1.0'


config timeserver 'ntp'
        list server '0.openwrt.pool.ntp.org'
        list server '1.openwrt.pool.ntp.org'
        list server '2.openwrt.pool.ntp.org'
        list server '3.openwrt.pool.ntp.org'

"ll /mnt/" outputs:

drwxr-xr-x    1 root     root          1024 Jan  9 12:07 ./
drwxr-xr-x    1 root     root          1024 Dec 31 16:42 ../
drwxr-xr-x    4 root     root          1024 Jan  9 12:21 log/

"ll /mnt/log/" outputs:

drwxr-xr-x    4 root     root          1024 Jan  9 12:21 ./
drwxr-xr-x    1 root     root          1024 Jan  9 12:07 ../
drwxr-xr-x    2 root     root          1024 Jan  9 12:21 snort/
drwxr-xr-x    2 root     root          1024 Jan 10 22:09 ulogd/

if I do these together:
"/etc/init.d/system restart" (no output; success)
"/etc/init.d/log restart" (no output; success)
"ll /mnt/log"

Then I finally see it, and it starts to work. Thank you... However...

drwxr-xr-x    4 root     root          1024 Jan 11 07:09 ./
drwxr-xr-x    1 root     root          1024 Jan  9 12:07 ../
-rw-------    1 root     root           152 Jan 11 07:10 openwrt.log
drwxr-xr-x    2 root     root          1024 Jan  9 12:21 snort/
drwxr-xr-x    2 root     root          1024 Jan 10 22:09 ulogd/

However, if I do this:
rm /mnt/log/openwrt.log
reboot
ll /mnt/log

drwxr-xr-x    4 root     root          1024 Jan 11  2023 ./
drwxr-xr-x    1 root     root          1024 Jan  9 12:07 ../
drwxr-xr-x    2 root     root          1024 Jan  9 12:21 snort/
drwxr-xr-x    2 root     root          1024 Jan 10 22:09 ulogd/

Based on the config files; it should work even though I reboot the router.
I still suspect it has something to do with boot order.

Try running /etc/init.d/log reload (not restart) so you don't lose the logs available in memory.

If it fixes the problem, insert the command into /etc/rc.local (above exit 0) and add some delay just in case.

sleep 10 && /etc/init.d/log reload
2 Likes
/etc/init.d/log reload
root@place:~# ll /mnt/log
drwxr-xr-x    4 root     root          1024 Jan 11 07:35 ./
drwxr-xr-x    1 root     root          1024 Jan  9 12:07 ../
-rw-------    1 root     root             0 Jan 11 07:35 openwrt.log
drwxr-xr-x    2 root     root          1024 Jan  9 12:21 snort/
drwxr-xr-x    2 root     root          1024 Jan 10 22:09 ulogd/

Yeah it worked; I'll add the line. Thank you.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.