in reply to Using STDERR and timestamps to write to a log file

I think you could set callbacks for $SIG{__DIE__} and $SIG{__WARN__}. Something in the lines of (untested):

$SIG{__DIE__} = sub {die log_error(shift) };#changed $_->shift $SIG{__WARN__} = sub {warn log_error(shift) };

Edited: Changed $_ to shift