I've created a service with reactphp which runs and does some stuff. It is started as a daemon so all output should be logged in a file. This log file should be named 'foo-log-file-$(date "+F")'. I want to have a single log file for each day.
As mentioned the script runs as a service, without stopping. The starting call for the script is therefore only done once.
php my_script.php >> /var/log/bar/log-file--$(date "+%F") 2>&1
So everything which is printed to the console from this script is saved into the file, but the file is only created with the date-string when it was called and is not updated with a new date.
Is it possible to solve this without writing the log logic in the php-script? Can i handle this requirement with bash?
FYI The answer of @fedorqui was a good approach, i solved it with a cronjob, which copies the file to a different one and empties the rest. You cannot use move, cause the through the running service, it is open all time and you get the error:
cannot move 'foo.log' to 'bar.log': Text file busy
So i cp it and clear the old one with:
cp foo.log foo.log.$(date +"%F");
cp /dev/null file.log;