OpenWrt Forum Archive

Topic: Help with logging to file

The content of this topic has been archived on 20 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Apologies for my lack of dev knowledge and general amateur hackiness,
I am running CC v15.05 and trying to get logging to to an external usb drive working. I have spent many hours reading and trying to understand how this works and have managed to come up with the following commands which are set in the browser client (system > startup > local startup) to run at start up:

mount -t ext4 -U <UID> /mnt/usbdrive -o rw
sleep 1
mkdir /mnt/usbdrive/logs/syslog/$(date +"%d.%m.%Y-%H.%M")
sleep 1
logread -f > /mnt/usbdrive/logs/syslog/$(date +"%d.%m.%Y-%H.%M")/logread.txt&
sleep 1
mkdir /mnt/usbdrive/logs/klog/$(date +"%d.%m.%Y-%H.%M")
sleep 1
dmesg > /mnt/usbdrive/logs/klog/$(date +"%d.%m.%Y-%H.%M")/dmesg.txt&
exit 0

I normally power off my unit every night so what I want to do is have openwrt log both logs to a seperate folder which it makes with the days date as the folder name when I power the unit on each day. To my immense surprise this actually works! but alas it only works intermittently at best, sometimes it logs every day for a few days and sometimes it doesnt work for weeks on end. I have tried adjusting the sleeps, taking them out, putting them back in and varying the lengths. But my knowledge is lacking on any thing else i can tinker with and i find myself unable to get this working reliably,
So I would be really grateful if someone could help me with this, any ideas or any help, pointers etc would be very much appreciated.

Cheers,
L

Not sure if this is related to your problem or not... I've made this mistake many times myself...

'>' = Overwrite log file
'>>' = Append to log file

Example:

echo "this is a test" > /tmp/tmplog
echo "this is not a test" > /tmp/tmplog
cat /tmp/tmplog

should produce

this is not a test

Or:

echo "this is a test" >> /tmp/tmplog
echo "this is not a test" >> /tmp/tmplog
cat /tmp/tmplog

should produce

this is a test
this is not a test

Be sure to either setup logrotate or clear the logs now and then... If you only need them temporarily, put them in /tmp and it clears when the machine reboots. This could also be the problem. Resources extremely limited on a router tongue

Cheers back to you tongue

(Last edited by mys5droid on 20 Feb 2017, 04:43)

I think I happened upon a solution to this, i installed "libdbi" (opkg install libdbi) and suddenly after 3 reboots in a row i am getting the new syslog/date.time, and klog/date.time folders each boot, each folder,containing the correct log as expected!
.

*Note libdbi did not solve my issue. It worked for 3 reboots after I installed libdbi but has only worked once since then. I think the problem may be something to do with openwrt not having a time immediately after startup, as it has to wait for the external modem to get a web connection before it can get time. but adding in a sleep of up to 300 seconds before the logread command still does not solve the problem.
I will continue trying to figure this out and post here if i find a solution.

I think I may have finally cracked this one, I found a config file at /etc/ulogd.conf which had a setting for the syslog that I experimented with ages ago, and that I long ago removed from the web interface. Makes me wonder if the web interface may be a little bit buggy?

When I use logread with -f the log records the subsequent entries, but misses out on the messages prior to the command running, without -f i get the prior messages. So I chain 2 commands to get all the data.
The commands that currently seem to be working when run at start up are as follows:
mkdir /mnt/usb/logs/syslog/$(date +"%d.%m.%Y-%H.%M") ; logread > /mnt/usb/logs/syslog/$(date +"%d.%m.%Y-%H.%M")/logread_st.txt ; logread -f > /mnt/usb/logs/syslog/$(date +"%d.%m.%Y-%H.%M")/logread.txt&
mkdir /mnt/lusb/logs/klog/$(date +"%d.%m.%Y-%H.%M") ; dmesg > /mnt/usb/logs/klog/$(date +"%d.%m.%Y-%H.%M")/dmesg.txt&
exit 0.

The discussion might have continued from here.