Singleton logger

Discussion in 'Perl' started by Laszlo, Apr 20, 2004.

  1. Laszlo

    Laszlo Guest

    Hi

    I need a GL::Logger wich implements Class::Singleton
    to be a singleton and Log::Log4perl to can log amy
    message into a file. Here is the module source:
    -------------------------------------------------------------------------
    package GL::Logger;

    use Class::Singleton;
    use vars qw( $ERROR );
    @ISA = qw(Class::Singleton);
    use Log::Log4perl;
    my $ERROR = '';
    my $logger;

    sub instance(){
    my $class = shift;
    my $self = bless { }, $class;
    Log::Log4perl::init('c:/log4perl/log4perl.conf');
    unless (defined ($self->{ $logger } = Log::Log4perl->get_logger('...'))) {
    $ERROR = "Cannot get configuration file (log4perl.conf)\n";
    return undef;
    }
    $self;
    }

    sub log(){
    my($level, $msg) = @_;
    if($level eq 'DEBUG'){
    $logger->debug($msg);
    }
    if($level eq 'INFO'){
    $logger->info($msg);
    }
    if($level eq 'WARN'){
    $logger->warn($msg);
    }
    if($level eq 'ERROR'){
    $logger->error($msg);
    }
    if($level eq 'FATAL'){
    $logger->fatal($msg);
    }
    return 0;
    }
    1;
    -------------------------------------------------------------------------

    And this is the way how I want to use it:

    -------------------------------------------------------------------------
    #!perl -w
    use GL::Logger;
    my $logger = GL::Logger->instance();
    $logger->log("ERROR", "blablabla");
    -------------------------------------------------------------------------

    It retunr the following error message:

    Use of uninitialized value in hash element at c:/Perl/site/lib/GL/Logger.pm line 14.

    What is wrong ?
    --------------------------------------------
    Laszlo Graf
     
    Laszlo, Apr 20, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sachin
    Replies:
    1
    Views:
    977
    Soren Kuula
    Feb 3, 2006
  2. Proton Projects - Moin

    Singleton - Whether Cloneable overrides Singleton

    Proton Projects - Moin, Mar 26, 2007, in forum: Java
    Replies:
    4
    Views:
    3,285
    Proton Projects - Moin
    Mar 27, 2007
  3. cap
    Replies:
    3
    Views:
    293
    James Edward Gray II
    Dec 11, 2005
  4. Georges Ko
    Replies:
    4
    Views:
    274
    Georges Ko
    Jul 26, 2006
  5. Wilhelm
    Replies:
    1
    Views:
    172
Loading...

Share This Page