title: Using Log::Log4perl with MCE (Many-core Engine) Perl
body: <p>I am using MCE for parallel processing for one of my project.
  I am facing issue while logging the output from MCE (for logging I am using Log4perl).</p>
  
  <p>I have gone through the examples provided and found them printing to STDOUT/STDERR or to some log file provided at that time.
  There is MCE->sendto() and MCE->print() option availble, but I am not sure how to use it with log4perl.</p>
  
  <pre><code>package ABC;
  use strict;
  use warnings;
  use MCE;
  
  sub new {
      my $class = shift;
      my ($self) = {@_};
      return bless $self, $class;
  }
  
  sub initialize_mce {
       my $mce = MCE-&gt;new(
          max_workers =&gt; 5,
          input_data =&gt; \@input_data,
          on_post_exit =&gt; \&amp;on_post_exit,
          user_begin =&gt; \&amp;user_begin,
          user_end   =&gt; \&amp;user_end,
          user_func =&gt; \&amp;run_function
      );
  
  }
  sub on_post_exit {
      my ($self, $e) = @_;
      # I want to write something like this -
      # I want to log to my global log file using Log4perl which is initialized in some other package and passed to this package
  
      # $self-&gt;{'logger'}-&gt;info("$e-&gt;{wid}: $e-&gt;{pid}: $e-&gt;{status}: $e-&gt;{msg}: $e-&gt;{id}");
  
      print "$e-&gt;{wid}: $e-&gt;{pid}: $e-&gt;{status}: $e-&gt;{msg}: $e-&gt;{id}\n";
  }
  
  sub user_begin {                   ## Called once at the beginning
      my ($self, $e) = @_;
      print "$$ start";
  }
  
  sub user_end {                     ## Called once at the end
      my $self = shift;
      #$self-&gt;{'logger'}-&gt;info("$$ end");
      print "$$ end";
  }
  
  sub run_function {
      my ($self) = @_;
      my $wid = MCE-&gt;wid;
      $self-&gt;{'logger'}-&gt;info("Running...$wid");
      my $input_data = $_;
      ###
      #Rest of subroutine 
      ####
  }
  1;
  </code></pre>