Ambrosia

 view release on metacpan or  search on metacpan

lib/Ambrosia/Logger.pm  view on Meta::CPAN

    my $self = shift;
    my $msg = shift;
    my $key = shift;
    if ( $msg )
    {
        if ( $self->{_time}->{$key} )
        {
            $self->log( $msg, " -::- ^^^^^^^^^^^^^^^^^^^ $key |", sprintf("%.4f", time - $self->{_time}->{$key} ) );
            delete $self->{_time}->{$key};
            return;
        }
        else
        {
            $self->log( $msg, " -::- vvvvvvvvvvvvvvvvvvv $key" );
        }
    }
    $self->{_time}->{$key} = time if $key;
}


sub __debug
{
    my ($self, @msg) = @_;
    my $p = __PACKAGE__;
    my $x = 0;
    my ($package, $line, $subroutine);
    my @callers;
 
    while ( do { package DB; ($package, $line, $subroutine) = (caller($x++))[0, 2, 3] } )
    {
        my @arg = $subroutine !~ /^$p\:\:/ ? @DB::args : ('...');
        unshift @callers, "\t$subroutine"
            . ( $subroutine ne '(eval)' ? ('( '.(join ", ", @arg).' )'):'')
            . ' At ' . $package
            . ' line ' . $line;
    }
    push @msg, "\nstack frames = [\n", (join "\n", @callers), "\n]";
    $self->log_info_ex(@msg);
}

sub __info_ex
{
    local $Data::Dumper::Indent = 1;
    shift->log( map { ref $_ ? Dumper($_) : $_ } @_);
}

sub __info
{
    shift->log( map { ref $_ ? ref $_ : $_ } @_);
}

sub DESTROY
{}

1;

__END__

=head1 NAME

Ambrosia::Logger - a class for create global object for logging.

=head1 VERSION

version 0.010

=head1 SYNOPSIS

    use Ambrosia::Logger;
    BEGIN {
        instance Ambrosia::Logger('myApplication', DEBUG => 1, INFO_EX => 1, INFO => 1, -prefix => 'GoogleCoupon_', -dir => $logger_path);
        Ambrosia::Logger::assign 'myApplication';
    }

    logger->log('is just message', 'other message' );
    logger->log_info('is simple info', ... );
    logger->log_info_ex('is dump of structures info', {foo=>1}, [{bar=>1},{baz=>2}] );
    logger->error('message about errors');
    logger->debug('write with the message and the stack of calls');

=head1 DESCRIPTION

C<Ambrosia::Logger> is a class for create global object for logging.
Implement the pattern B<Singleton>.

=head2 instance

Instances the named object of type C<Ambrosia::Logger> in the pool.
This method not exported. Use as constructor: C<instance Ambrosia::Logger(.....)>

=head2 logger

Returns the global object of type C<Ambrosia::Logger>.
C<logger(name)> - the name is optional param. Call with name if you not assign current process to logger yet.

=head2 assign

Assigns current process to the global named object of type C<Ambrosia::Logger>.

=head1 DEPENDENCIES

L<File::Path>
L<IO::File>
L<Data::Dumper>
L<Time::HiRes>
L<Scalar::Util>
L<Exporter>
L<Ambrosia::error::Exceptions>

=head1 THREADS

Not tested.

=head1 BUGS

Please report bugs relevant to C<Ambrosia> to <knm[at]cpan.org>.

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2010-2012 Nickolay Kuritsyn. All rights reserved.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 AUTHOR

Nikolay Kuritsyn (knm[at]cpan.org)

=cut



( run in 1.961 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )