Changeset 388

Show
Ignore:
Timestamp:
12/19/01 01:46:39
Author:
miyagawa
Message:

caller stack

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Log-Dispatch-Config/trunk/Changes

    r386 r388  
    11Revision history for Perl extension Log::Dispatch::Config. 
    22 
    3 0.07 
     30.07  Wed Dec 19 01:46:00 JST 2001 
    44        - forgot to update MANIFEST 
     5        * Add $Log::Dispatch::Config::CallerDepth variable 
     6          (Thanks to Matt Sergeant <matt@sergeant.org>) 
     7        - Call caller() function only when necessary 
    58 
    690.06  Tue Dec 18 21:27:51 JST 2001 
     
    1215        - Deprecated ${XXX} style format 
    1316        - Switched to fully qualified variable from use vars (for inheritance) 
     17        * Allows .ini style grouping in AppConfig 
    1418 
    15190.05  Thu Dec  6 19:05:11 JST 2001 
  • Log-Dispatch-Config/trunk/MANIFEST

    r385 r388  
    1616t/08_datetime.t 
    1717t/09_ini.t 
     18t/10_caller.t 
    1819t/date.cfg 
    1920t/log.cfg 
  • Log-Dispatch-Config/trunk/README

    r381 r388  
    181181          } 
    182182 
    183         "get_attes" accepts name of a dispatcher and should return hash 
     183        "get_attrs" accepts name of a dispatcher and should return hash 
    184184        reference of parameters associated with the dispatcher. 
    185185 
     
    259259 
    260260SEE ALSO 
    261     the Log::Dispatch manpage, the AppConfig manpage 
    262  
     261    the Log::Dispatch::Configurator::AppConfig manpage, the Log::Dispatch 
     262    manpage, the AppConfig manpage 
     263 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Config.pm

    r383 r388  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.06'; 
     5$VERSION = '0.07'; 
    66 
    77require Log::Dispatch; 
    88use base qw(Log::Dispatch); 
    99use fields qw(config ctime); 
     10 
     11# caller depth: can be changed from outside 
     12$Log::Dispatch::Config::CallerDepth = 3; 
    1013 
    1114sub configure { 
     
    6770 
    6871    my $global = $config->get_attrs_global; 
    69     my $callback = $class->format_to_cb($global->{format}, 3); 
     72    my $callback = $class->format_to_cb($global->{format}, 0); 
    7073    my %dispatchers; 
    7174    foreach my $disp (@{$global->{dispatchers}}) { 
    7275        $dispatchers{$disp} = $class->config_dispatcher( 
    73                 $disp, $config->get_attrs($disp), 
    74             ); 
     76           $disp, $config->get_attrs($disp), 
     77        ); 
    7578    } 
    7679    my %args; 
     
    105108 
    106109    if (exists $var->{format}) { 
    107         $var->{callbacks} = $class->format_to_cb(delete $var->{format}, 5); 
     110        $var->{callbacks} = $class->format_to_cb(delete $var->{format}, 2); 
    108111    } 
    109112    return $var; 
     
    122125    return undef unless defined $format; 
    123126 
     127    my $needs_caller = $format =~ /%[FLP]/; 
    124128    return sub { 
    125129        my %p = @_; 
    126         @p{qw(package filename line)} = caller($stack); 
     130 
     131        # caller() might be slow 
     132        if ($needs_caller) { 
     133            my $depth = $Log$ 
     134            my $depth = Revision 1.15  2001/12/18 16:46:39  miyagawa 
     135            my $depth = caller stack 
     136            my $depth =stack; 
     137            @p{qw(package filename line)} = caller($depth); 
     138        } 
    127139 
    128140        my $log = $format; 
     
    260272dispatchers. This parameter is B<optional>. 
    261273 
     274See L</"CALLER STACK"> for details about package, line number and 
     275filename. 
     276 
    262277=back 
    263278 
     
    359374  } 
    360375 
    361 C<get_attes> accepts name of a dispatcher and should return hash 
     376C<get_attrs> accepts name of a dispatcher and should return hash 
    362377reference of parameters associated with the dispatcher. 
    363378 
     
    432447=back 
    433448 
    434 =head1 TODO 
    435  
    436 =over 4 
    437  
    438 =item * 
    439  
    440 LogLevel configuration depending on caller package like log4j? 
    441  
    442 =back 
     449=head1 CALLER STACK 
     450 
     451When you call logging method from your subroutines / methods, caller 
     452stack would increase and thus you can't see where the log really comes 
     453from. 
     454 
     455  package Logger; 
     456  my $Logger = Log::Dispatch::Config->instance; 
     457 
     458  sub logit { 
     459      my($class, $level, $msg) = @_; 
     460      $Logger->$level($msg); 
     461  } 
     462 
     463  package main; 
     464  Logger->logit('debug', 'foobar'); 
     465 
     466You can adjust package variable C<$Log::Dispatch::Config::CallerDepth> 
     467to change the caller stack depth. The default value is 3, (which 
     468depends heavily on Log::Dispatch's undocumented implementation. It 
     469might be changed in future). 
     470 
     471  sub logit { 
     472      my($class, $level, $msg) = @_; 
     473      local $Log::Dispatch::Config::CallerDepth = 4; 
     474      $Logger->$level($msg); 
     475  } 
    443476 
    444477=head1 AUTHOR