in reply to Passing filehandles
print { $self->{_fh} } $self->{_separator}, $status, $self->{_separator}, $message, "\n";
And modify _init to receive this filehandle somehow:
# following the example of how you did seperator: $self->{_fh} = $args->{fh};
To use this, pass a filehandle to the constructor. With modern perls this can be a lexical.
open my $logger_fh, ">/tmp/log.log" or die...; my $logger = LoggerClass->new({ fh => $fh });
You need to do some work, perhaps, to make STDOUT (or STDERR?) the default. You also have to turn on autoflushing on the correct filehandle. (But note that most filehandles, even when buffered, are line buffered on output; and since _write always appends a newline this step may not be required. YMMV.)
|
|---|