bliako has asked for the wisdom of the Perl Monks concerning the following question:

I see random complains like below when I instantiate a WWW::Mechanize::Chrome object:

Log4perl: Seems like no initialization happened. Forgot to call init() +? 23:28:21 Sent 'Target.closeTarget' message $VAR1 = '{"id":11,"params": +{"targetId":"F75959D2137237798CF1FCB89E87FFAA"},"method":"Target.clos +eTarget"}'; 23:28:21 Can't call method "irand" on an undefined value at (eval 140) + line 17 during global destruction.

As an example, consider the following test-script. For me, the below script sometimes passes and sometimes it fails (see below for when exactly), although all subtests succeed all the time.

#!/usr/bin/env perl use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); # This is for the mech obj, Set priority of root logger to ERROR Log::Log4perl->easy_init($ERROR); my %default_mech_params = ( headless => 1, # log => $mylogger, launch_arg => [ '--window-size=600x800', '--password-store=basic', # do not ask me for stupid chrome ac +count password # '--remote-debugging-port=9223', # '--enable-logging', # see also log above '--disable-gpu', '--no-sandbox', '--ignore-certificate-errors', '--disable-background-networking', '--disable-client-side-phishing-detection', '--disable-component-update', '--disable-hang-monitor', '--disable-save-password-bubble', '--disable-default-apps', '--disable-infobars', '--disable-popup-blocking', ], ); my $mech_obj = WWW::Mechanize::Chrome->new(%default_mech_params); ok(defined($mech_obj), "WWW::Mechanize::Chrome->new() : called.") or B +AIL_OUT("failed to create WWW::Mechanize::Chrome object"); done_testing();

Here is what it says when I run make all && make test. Note that this fails all the time.

Manifying 1 pod document PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::H +arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/l +ib', 'blib/arch')" t/*.t t/xx.t .. 1/? Log4perl: Seems like no initialization happened. Forgot +to call init()? 2025/08/11 23:40:43 Sent 'Target.closeTarget' message $VAR1 = '{"metho +d":"Target.closeTarget","id":11,"params":{"targetId":"FF3672A330F5788 +556F1B4B18CCC5610"}}'; 2025/08/11 23:40:43 Can't call method "irand" on an undefined value at + (eval 140) line 17 during global destruction. t/xx.t .. Dubious, test returned 255 (wstat 65280, 0xff00) All 1 subtests passed Test Summary Report ------------------- t/xx.t (Wstat: 65280 (exited 255) Tests: 1 Failed: 0) Non-zero exit status: 255 Files=1, Tests=1, 11 wallclock secs ( 0.03 usr 0.00 sys + 0.41 cusr + 0.12 csys = 0.56 CPU) Result: FAIL Failed 1/1 test programs. 0/1 subtests failed. make: *** [Makefile:873: test_dynamic] Error 255

However, when I run make all && perl -Iblib/lib t/xx.t, sometimes it fails with above complaining and sometimes it succeeds.

I use the latest W:M:C v0.73. It fails with perl v5.40.2. On another computer with perl v5.38.2 I see no failures (after 10 consecutive runs). Both running latest linux.

Thanks, bw, bliako

ps. my question is not urgent, don't stop swimming to answer it...

ps2. OT but Corion does the dreadful Log4* abomination Log::Log4perl need to be used by WWW::Mechanize::Chrome?

  • Comment on WWW::Mechanize::Chrome : random complaining that Log4perl is not initialised and test fails
  • Select or Download Code

Replies are listed 'Best First'.
Re: WWW::Mechanize::Chrome : random complaining that Log4perl is not initialised and test fails
by Corion (Patriarch) on Aug 12, 2025 at 07:40 UTC

    I'm not sure that Log::Log4perl is a good logging mechanism, but all others seem equally bad to me.

      Have you looked at Log::Any? It's pretty lightweight, has sensible defaults and means that I, as the module writer, don't need to make any arbitrary decisions about how the user of my module wants their logging set up.


      🦛

      What's wrong with Log::Log4perl ?

        To me, Log::Log4perl requires a lot of configuration to set up properly and I feel it could do with more convenient ways to switch log-producing locations on and off.

        On the other hand, Log::Log4perl can be configured to separate out different logging messages and different logging sources into different output streams, so it's not all bad if you have a larger application of which WWW::Mechanize::Chrome is just a part.

        IMHO It's less about what is wrong with Log4perl and more about what is wrong with releasing a CPAN module that depends on Log4perl. If WWW::Mechanize::Chrome had been built on Log::Any, this unit test would be able to plug it into (my) Log::Any::Adapter::TAP and have the log messages be an official part of the TAP stream. Meanwhile people using WWW::Mechanize::Chrome in production could plug it into Log4perl if they want really fancy logging and everyone goes home happy.

        Personally I never use Log4perl because I subscribe to daemontools philosophy that all logging of a service should stream through stderr and a separate dedicated logger process should read that pipe and handle all the advanced logic to sort/filter log messages. I like the separation of concerns better than trying to put advanced logging configuration into each perl service.