From: Jarmo on
I have a problem and I was hoping someone could help me. I have a program
that every time it runs it saves a log file with same name about the changes
it did on that particular run. Result is that old file gets overwritten and
lost. I would like to create "virtual file" so that every time foobar.log is
written I actually end up with a file that has date and time added to it.

In other words:
I run application that writes to "foobar.log" and I want the file actually
go to "~/foobarlogs/foobarYYYY-MM-DD-HH-MM-SS.log" instead.

I know I did something similar years ago with perl but my
programming/scripting skills are too rusty to accomplish it anymore on my
own. I would greatly appreciate the help.

Jarmo
From: RedGrittyBrick on
On 16/02/2010 15:29, Jarmo wrote:
> I have a problem and I was hoping someone could help me. I have a program
> that every time it runs it saves a log file with same name about the changes
> it did on that particular run. Result is that old file gets overwritten and
> lost. I would like to create "virtual file" so that every time foobar.log is
> written I actually end up with a file that has date and time added to it.
>
> In other words:
> I run application that writes to "foobar.log" and I want the file actually
> go to "~/foobarlogs/foobarYYYY-MM-DD-HH-MM-SS.log" instead.
>
> I know I did something similar years ago with perl but my
> programming/scripting skills are too rusty to accomplish it anymore on my
> own. I would greatly appreciate the help.

The obvious (to me) answer is not to run the program directly but run it
from a script. The script can rename the logfile after the program exits.

For a Perl solution, the following might be a useful starting point.
perldoc -f system
perldoc -f localtime
perldoc -f rename

You could also do this quite easily in any of the popular Unix shells.
man date
From: ccc31807 on
On Feb 16, 10:29 am, Jarmo <ja...(a)darkbusstop.com> wrote:
> lost. I would like to create "virtual file" so that every time foobar.log is
> written I actually end up with a file that has date and time added to it.

#make log file name with time string
my ($s, $m, $h, $d, $m, $y, @r) = localtime();
my $timestring = sprintf ("%d-%02d-%02d-%02d-%02d-%02s", $y + 1900, $m
+ 1, $d, $h, $m, $s);
my $logfile = "log_${timestring}.txt";
#open log file
open LOG, '>', $logfile;
#write to log
close LOG;

Better, in my opinion, is to use the append operator ('>>') and write
to the same file daily, but this depends on the quantity of logging
you do.

CC
From: J�rgen Exner on
Jarmo <jampe(a)darkbusstop.com> wrote:
>I have a problem and I was hoping someone could help me. I have a program
>that every time it runs it saves a log file with same name about the changes
>it did on that particular run. Result is that old file gets overwritten and
>lost. I would like to create "virtual file" so that every time foobar.log is
>written I actually end up with a file that has date and time added to it.
>
>In other words:
>I run application that writes to "foobar.log" and I want the file actually
>go to "~/foobarlogs/foobarYYYY-MM-DD-HH-MM-SS.log" instead.

Not a Perl solution but what about running a cron job at midnight which
does a
ln -s foobar.log foobar[whateverthenewdayis]

jue
From: Uri Guttman on
>>>>> "c" == ccc31807 <cartercc(a)gmail.com> writes:

c> On Feb 16, 10:29�am, Jarmo <ja...(a)darkbusstop.com> wrote:
>> lost. I would like to create "virtual file" so that every time foobar.log is
>> written I actually end up with a file that has date and time added to it.

c> #make log file name with time string
c> my ($s, $m, $h, $d, $m, $y, @r) = localtime();
c> my $timestring = sprintf ("%d-%02d-%02d-%02d-%02d-%02s", $y + 1900, $m
c> + 1, $d, $h, $m, $s);

GACK!! please use POSIX::strftime. i hate seeing hand made date
formatting. all you need is in that one sub and with less cruft and
noise and chance for errors.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------