Skip to content

Log::Dispatch::File should not explicitly close the filehandle; rely on garbage collection instead #73

@damil

Description

@damil

If a logger is cloned, it will hold a copy of the logging filehandle. When the clone is destroyed, Log::Dispatch::File should not close the filehandle, because the original logger object might still be alive. Instead of an explicit close, just rely on the garbage collector : it will automatically close the file when the last reference is destroyed.

Below is a simple demonstration of the problem :


use Log::Dispatch;
use Clone qw(clone);

my $obj = {log => Log::Dispatch->new(outputs => [
  ['Screen', min_level => 'debug', newline => 1                          ],
  ['File',   min_level => 'debug', newline => 1, filename => 'foobar.log'],
 ])};
my $clone = clone $obj;
$obj->{log}->info('cloned');
undef $clone;
$obj->{log}->info('after delete');

This produces an error "print() on closed filehandle"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions