package Log::Caller;
use strict;
use warnings;
sub _exports {qw[ log_debug log_info log_error log_warn log_fatal ]}
use Sub::Exporter -setup => {
    exports => { map { $_ => \&_build_log_msg } _exports() },
    groups  => { all => [ _exports() ] },
};

our $VERSION = '0.03';

sub _msg {
    my ( $params, $pkg, $fn, $ln, @yarrgs ) = @_;
    my($lvl,$prefix,$fh) = @$params{qw/lvl prefix fh/};
    $fh ||= *STDERR;
    $prefix = $prefix ? $prefix." " : "";
    my $format = shift @yarrgs || '';
    my $msg = sprintf( $format, (@yarrgs) );
    print $fh $prefix."[$lvl] $msg at $fn line $ln.\n";
    
}


sub _build_log_msg {
    my ( $class, $log_func, $params ) = @_;
    $log_func =~ s/^log_//g;
    $params ||= {};
    return sub {
        _msg( { %$params, lvl => $log_func, }, caller, @_ );
    };
}

1;
__END__

=head1 NAME

Log::Caller

=head1 SYNOPSIS

 log_debug "scanning new data...";

 [debug] scanning new data...  at t/00compile.t line 6

 log_warn "client %d not found!",$id;

 [warn] client 123 not found! at t/00compile.t line 8

=head1 DESCRIPTION
 

=over 4

=item log_$level EXPR LIST

Take EXPR as a sprintf pattern and evaluate it with LIST if defined, print it to STDERR or the provided filehandle.

=back

=head1 EXPORT

=head2 Configuration

 use Log::Caller ":all";

 use Log::Caller qw[ log_debug log_warn ];

 use Log::Caller ":all" => { prefix => ' <prefixin>' };
 
 my $fh;
 BEGIN { open( $fh, ">", "outs.txt" ) or die "$@ $!" };
 use Log::Caller (
    "log_debug" => { prefix => 'prefix1>', fh => $fh },
    "log_warn" => { prefix => 'prefixDos::' },
    );
        


The following functions are available for export:

log_debug, log_info, log_error, log_warn, log_fatal,

The :all tag is also available for importing all.

=head1 JUSTIFICATION

There are scores of loggers out there, of varying usefulness, yet I still find myself and others constantly putting 
warn "blah" everywhere in the code. 

Why? 

a) because we're lazy, and it's the lowest effort form of logging output for debugging.

b) the call stack is appended nicely

c) because most loggers are full of bloat

I wanted something that would work like warn but be filterable with proper log levels.

=head1 SEE ALSO

L<Log::Fu> - A configurable logger with caller context among other features.

=head1 AUTHOR

 sam@socialflow.com, sponsored by SocialFlow, Inc.

=head1 COPYRIGHT & LICENSE

Copyright 2012, Sam Kaufman skaufman@cpan.org

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