title: Can not create a basic logger in Perl
body: <p>I am reading about <code>Log4Perl</code> from <a href="http://www.perl.com/pub/2002/09/11/log4perl.html" rel="nofollow">perl.com</a><br>
  I am trying to follow the tutorial but got "lost" in the part <code>Logger Categories</code>.<br>
  I tried to follow the tutorial and did the following scripts:  </p>
  
  <p>I created a directory <code>Groceries</code> and inside I created a <code>pm</code> file as follows:<br>
  Food.pm:  </p>
  
  <pre><code>#!/usr/bin/perl  
  use strict;  
  use warnings;  
  
  package Groceries::Food;  
  
  use Log::Log4perl qw(get_logger);  
  
  sub new {  
         my($class, $what) = @_;  
         my $logger = get_logger("Groceries::Food");  
         if(defined $what) {  
              $logger-&gt;debug("New food: $what");  
              return bless { what =&gt; $what }, $class;  
         }  
         $logger-&gt;error("No food defined");  
         return undef;  
  }  
  sub consume {  
          my($self) = @_;  
          my $logger = get_logger("Groceries::Food");  
          $logger-&gt;info("Eating $self-&gt;{what}");  
  }  
  </code></pre>
  
  <p>This is copy/paste from perl.com mentioned above.<br>
  Then in the same directory that <code>Groceries</code> directories is in (i.e. not in the same directory that <code>Food.pm</code> resides) I created another script as follows:<br>
  test_script.pl:  </p>
  
  <pre><code>#!/usr/bin/perl  
  use strict;  
  use warnings;  
  
  ######### System initialization section ###  
  use Log::Log4perl qw(get_logger :levels);  
  my $food_logger = get_logger("Groceries");   
  $food_logger-&gt;level($INFO);   
  
  sub test_log(){  
          my $what = @_;  
          if(defined $what){  
                  $food_logger-&gt;info("Defined:", $what);  
          }  
          else{  
                  $food_logger-&gt;error("Nothing defined");  
          }  
  }  
  
  test_log();  
  </code></pre>
  
  <p>But when I run the test script it does not work. I get:  </p>
  
  <p><code>Log4perl: Seems like no initialization happened. Forgot to call init()?</code>  </p>
  
  <p>Also if I add:<br>
  <code>test_log("something");</code>  </p>
  
  <p>I get:     </p>
  
  <pre><code>Too many arguments for main::test_log at testlogger.pl line 23, near ""something")" 
  Execution of testlogger.pl aborted due to compilation errors.   
  </code></pre>
  
  <p>What am I doing wrong here?   </p>
  
  <p><strong>UPDATE</strong><br>
  I followed the tutorial and modified the way it says at <code>listing 2: eat.pl</code>   </p>
  
  <pre><code>#!/usr/bin/perl  
  use strict;  
  use warnings;  
  
  use Log::Log4perl qw(get_logger :levels);  
  
  ######### System initialization section ###  
  my $food_logger = get_logger("Groceries::Food");  
  $food_logger-&gt;level($INFO);  
  
  #############Run it ###  
  my $o = Groceries::Food-&gt;new("Chicken");  
  $o-&gt;consume();  
  
  ####Application section ####  
  package Groceries::Food;  
  
  use Log::Log4perl qw(get_logger);  
  
  sub new {  
         my($class, $what) = @_;  
         my $logger = $food_logger;#get_logger("Groceries::Food");  
         if(defined $what) {  
              $logger-&gt;debug("New food: $what");  
              return bless { what =&gt; $what }, $class;  
         }  
         $logger-&gt;error("No food defined");  
         return undef;  
  }  
  
  
  sub consume {  
          my($self) = @_;  
          my $logger = $food_logger;#get_logger("Groceries::Food");  
          $logger-&gt;info("Eating $self-&gt;{what}");  
  }  
  </code></pre>
  
  <p>I still get <code>Log4perl: Seems like no initialization happened. Forgot to call init()?</code></p>