logging - Problems appending to a file in perl -
i have problem logging messages in perl. created simple log package. still first row file. seems there appending file not working. ideas?
even when run script more times, there arent changes in output log file. there written "something". need append "somethingelse" output file. have mistake in log?
package logger; sub new { $package = shift; $self = {}; bless $self , $package; $self->initialize(@_); return $self; } sub initialize { $self = shift; $self->{logfile} = shift; return; } sub logger { $self = shift; $message = shift; (undef,$script, $line) = caller; open(log, ">>$self->{logfile}"); print log substr(scalar localtime(),4,15), " ", $message, "\n"; close(log); return; } $log = logger->new('/usr/local/logs/test.log'); $log->logger("something"); $log->logger("somethingelse"); thank
this code works fine me, can't sure correct solution, when code doesn't print want to, it's because of autoflush problem. try adding this:
$| = 1 or if prefer:
use english qw( -no_match_vars ); $output_autoflush = 1; to beginning of program , see if helps.
Comments
Post a Comment