Short answer
GNU Parallel has a set of nice options which make it really easy to do such things:
parallel --tagstring "{}:" --line-buffer tail -f {} ::: one.log two.log
The output would be:
one.log: contents of one.log here...
one.log: contents of one.log here...
two.log: contents of two.log here...
two.log: contents of two.log here...
More explanation
- The option
--tagstring=str tags each output line with string str. From parallel man page:
--tagstring str
Tag lines with a string. Each output line will be prepended with
str and TAB (\t). str can contain replacement strings such as {}.
--tagstring is ignored when using -u, --onall, and --nonall.
All occurrences of {} will be replace by parallel's arguments which, in this case, are log file names; i.e. one.log and two.log (all arguments after :::).
The option --line-buffer is required because the output of a command (e.g. tail -f one.log or tail -f two.log) would be printed if that command is finished. Since tail -f will wait for file growth, it is required to print the output on line basis which --line-buffer does so. Again from parallel man page:
--line-buffer (alpha testing)
Buffer output on line basis. --group will keep the output
together for a whole job. --ungroup allows output to mixup with
half a line coming from one job and half a line coming from
another job. --line-buffer fits between these two: GNU parallel
will print a full line, but will allow for mixing lines of
different jobs.
-v(verbose) option for tail . This may not exactly match your ask, but is a start. – rahul Apr 13 '15 at 10:23