Here's an imaginary command line where "pushtolog" is a utility that accepts lines of text from a pipe and logs them into a file with a filename incorporating today's date:
tail -F mylatestlogfile.log | grep "ERROR" | pushtolog -d /tmp/myerrors/ -f yyyy-MM-dd -r errors -e log
When running on the 17th Feb 2017 the output would be logged to file:
/tmp/myerrors/errors.2017-02-17.log
At midnight on 18th Feb 2017, this file would be closed and any further output would be logged to file:
/tmp/myerrors/errors.2017-02-18.log
The switchover would happen automatically. Performance is fairly irrelevant due to a low volume of relevant log lines, so in the worst case it would be fine for the utility to check the date every time it wrote a log line.
The GNU/Linux server that this will run on has a minimal set of utilities installed. It has Python 2 installed, and I could write a utility myself. Before taking that step, it's sensible to ask whether there is a tool that will already the job, or whether there's an idiomatic alternative way of doing this.
logrotate is available, but I'd rather avoid doing a rotation every because it seems "simpler" to have it all done in step.
multilog seems to tackle a similar problem of switching target log file, but when the log file is full rather than when the date changes. I don't have root access and can't run a package manager to get hold of it; I haven't investigated whether I could build it from source successfully using the permissions that I have. If it's clearly the tool for the job then I'll pursue this option.
-f $(date +"%Y-%m-%d")
– Lambert Feb 17 '17 at 11:11In my imaginary example, I set the date format to year-month-day using the -f switch. I don't want that to be evaluated once today, because it needs to take a different value tomorrow. The utility needs the date format, not the current date.
– David B Feb 17 '17 at 11:17-r
and-e
? – Lambert Feb 17 '17 at 11:28