houseabsolute / Log-Dispatch

Dispatches messages to one or more outputs
https://metacpan.org/release/Log-Dispatch/
Other
12 stars 29 forks source link

fix threads usage with Perl 5.20 #9

Closed schweikert closed 9 years ago

schweikert commented 9 years ago

Without this patch I get:

lock can only be used on shared values at /opt/OSAGperlm/lib/Log/Dispatch/Syslog.pm line 86.
autarch commented 9 years ago

Thanks, I applied a version of this change from the command line.

schweikert commented 9 years ago

Note that it didn't work without the '&' for me under certain conditions. That's why I modified it as follows: https://github.com/open-ch/Log-Dispatch/commit/7f2c7a3728781c81455bd10b02f0cbeff41a453e I can try to reproduce the issue...

schweikert commented 9 years ago

I can reproduce the issue.

#!/usr/bin/perl -w

use Log::Dispatch;
use threads;
use threads::shared;

my $log = Log::Dispatch->new(
    outputs => [
        [
            'Syslog',
            min_level => 'info',
            ident     => 'Yadda yadda'
        ]
    ],
    lock => 1,
);

$log->emerg("Time to die.");

$ ./test-lock.pl Type of arg 1 to threads::shared::share must be one of [$@%](not single ref constructor) at /opt/OSAGperlm/lib/Log/Dispatch/Syslog.pm line 67, near "$thread_lock)" Compilation failed in require at /opt/OSAGperlm/lib/Module/Runtime.pm line 317.

If I add the '&', it works.

autarch commented 9 years ago

I did write a test for this - https://github.com/houseabsolute/Log-Dispatch/blob/master/t/06-syslog.t

It passed on Travis - https://travis-ci.org/houseabsolute/Log-Dispatch/builds/74317771

It'd be great to reproduce this in a test somehow.

autarch commented 9 years ago

Aha, I was able to reproduce it