logger
only logs to the syslog - if you really want to do things this way, then you would have to first edit your syslog.conf
file and add something like this:
# node.js logging
local5.* /home/pi/logs/nodejs.log
local5
is a predefined facility, make sure it is not in use elsewhere in your syslog conf. Now you need to restart the syslog service:
/etc/init.d/syslog stop; /etc/init.d/syslog start
And now you can use logger
to log your messages:
sudo /opt/node/bin/node /home/pi/www/js/script.js | logger -p local5.info
To have a different log file for each date, you would have to use something like logrotate
.
An alternative (better) solution would be to prepend the timestamp to each line before you log it:
while read msg; do
echo -n "[$(date +"%d/%m/%Y %H:%M:%S")] " >> "$LOGFILE"
echo "$msg" >> "$LOGFILE"
done < <(sudo /opt/node/bin/node /home/pi/www/js/script.js)