1 (edited by Lord Flasheart 2017-01-25 09:36:47)

Topic: Help with logging to file

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

2 (edited by mys5droid 2017-02-20 04:43:49)

Re: Help with logging to file

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

Re: Help with logging to file

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!
.