io redirection - How to pipe output to a rotating log file in shell, like log4j does? -


i'm using io redirection log output log file. want able move log different file whenever current day changes, such 2017-08-18.log.

my attempts included use >xxx.log redirection clear log file, content reappeared within new log?

how set log redirection? thanks.

if ok perl run little script:

use posix qw(strftime);  $fbase = "tmp-%y-%m-%d-%h-%m.log";  while(<>) {   $fnamenew = strftime $fbase, localtime;    if ($fnamenew ne $fname)   {     print "logging to: $fnamenew\n";     $fname = $fnamenew;     close out;     open out, ">$fname";   }   print out $_; } 

use like: $mycomputation | perl script.pl. append input filename built given time pattern, here tmp-yyyy-mm-dd-hh-mi.log. on each new line of input, pattern rebuilt , checked against old one. should differ input piped new file , old 1 closed.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -