Changeset 409

Show
Ignore:
Timestamp:
12/27/01 15:01:23
Author:
miyagawa
Message:

version up

Files:

Legend:

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

    r391 r409  
    11Revision history for Perl extension Log::Dispatch::Config. 
     2 
     30.09  Thu Dec 27 15:01:12 JST 2001 
     4        - Fixed unnecessary quotes with 'format' 
     5        - Clean up format_to_cb code 
     6        - '%%' is replaced by '%' 
     7        * [API change] $CallerDepth defaults to 0 
     8        - caller() code is now independent of L::D implementation 
     9          (Thanks to Dave Rolsky <autarch@urth.org>) 
     10 
     110.08  Sat Dec 22 15:58:20 JST 2001 
     12        - Added dependency on File::Temp in Makefile.PL 
     13          (Thanks to Matt Sergeant <matt@sergeant.org>) 
     14        - Workaround against broken base.pm 
    215 
    3160.07  Wed Dec 19 01:46:00 JST 2001 
    417        - forgot to update MANIFEST 
    5         * Add $Log::Dispatch::Config::CallerDepth variable 
    6         Call caller() function only when necessary 
     18        * Added $Log::Dispatch::Config::CallerDepth variable 
     19        - Call caller() function only when necessary 
    720          (Thanks to Matt Sergeant <matt@sergeant.org>) 
    821 
    9220.06  Tue Dec 18 21:27:51 JST 2001 
    10         --- developer API change --- 
    11         * Added Log::Dispatch::Configurator and docs/tests for it 
     23        * Added Log::Dispatch::Configurator 
    1224          (Thanks to Matt Sergeant <matt@sergeant.org>) 
    13         * Added Date/Time format configuration 
     25        * [API change] Added Date/Time format configuration 
    1426          (Thanks to Matt Sergeant) 
    15         - Deprecated ${XXX} style format 
     27        - [API change] Deprecated ${XXX} style format 
    1628        - Switched to fully qualified variable from use vars (for inheritance) 
    1729        * Allows .ini style grouping in AppConfig 
     
    2133 
    22340.04  Thu Dec  6 18:33:50 JST 2001 
    23         --- API change (with backward compatibility) --- 
    24         * Whole architecture redesign: now inherits from Log::Dispatch. 
     35        * Now inherits from Log::Dispatch. 
     36        * [API change] Added Log::Dispatch::Config->instance 
    2537 
    26380.03  Tue Dec  4 11:33:15 JST 2001 
  • Log-Dispatch-Config/trunk/Makefile.PL

    r382 r409  
    11use ExtUtils::MakeMaker; 
    22 
    3 $LAST_API_CHANGE = 0.05
     3$LAST_API_CHANGE = 0.08
    44eval q{require Log::Dispatch::Config}; 
    55unless ($@) { 
     
    2222        AppConfig => 1.52, 
    2323        IO::Scalar => 0, 
     24        File::Temp => 0.12, 
    2425    }, 
    2526); 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Config.pm

    r390 r409  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.07'; 
    6  
    7 require Log::Dispatch; 
     5$VERSION = '0.08_01'; 
     6 
     7use Log::Dispatch; 
    88use base qw(Log::Dispatch); 
    99use fields qw(config ctime); 
    1010 
    1111# caller depth: can be changed from outside 
    12 $Log::Dispatch::Config::CallerDepth = 3
     12$Log::Dispatch::Config::CallerDepth = 0
    1313 
    1414sub configure { 
     
    113113} 
    114114 
    115 my %syn = ( 
    116     p => 'level', 
    117     m => 'message', 
    118     F => 'filename', 
    119     L => 'line', 
    120     P => 'package', 
    121 ); 
    122  
    123115sub format_to_cb { 
    124116    my($class, $format, $stack) = @_; 
    125117    return undef unless defined $format; 
    126118 
     119    # caller() called only when necessary 
    127120    my $needs_caller = $format =~ /%[FLP]/; 
    128121    return sub { 
    129122        my %p = @_; 
    130  
    131         # caller() might be slow 
    132         if ($needs_caller) { 
    133             my $depth = $Log::Dispatch::Config::CallerDepth 
    134                 + $stack; 
    135             @p{qw(package filename line)} = caller($depth); 
    136         } 
     123        $p{p} = delete $p{level}; 
     124        $p{m} = delete $p{message}; 
     125        $p{n} = "\n"; 
     126        $p{'%'} = '%'; 
     127 
     128        if ($needs_caller) { 
     129            my $depth = 0; 
     130            $depth++ while caller($depth) =~ /^Log::Dispatch/; 
     131            $depth += $Log::Dispatch::Config::CallerDepth; 
     132            @p{qw(P F L)} = caller($depth); 
     133        } 
    137134 
    138135        my $log = $format; 
    139         $log =~ s/%n/\n/g; 
    140136        $log =~ s/%d(?:{(.*?)})?/$1 ? _strftime($1) : scalar localtime/eg; 
    141         $log =~ s/%([pmFLP])/$p{$syn{$1}}/g; 
     137        $log =~ s/%([%pmFLPn])/$p{$1}/g; 
    142138 
    143139        return $log; 
     
    173169 
    174170  my $dispatcher = Log::Dispatch::Config->instance; 
     171  $dispatcher->debug('this is debug message'); 
     172  $dispatcher->emergency('something *bad* happened!'); 
    175173 
    176174  # or the same 
     
    256254  %L    line number 
    257255  %P    package 
    258   %n    newline (\n) 
     256  %n    newline (\n) 
     257  %%    % itself 
    259258 
    260259Note that datetime (%d) format is configurable by passing C<strftime> 
     
    367366      my $self = shift; 
    368367      return { 
    369           'format' => undef, 
     368          format => undef, 
    370369          dispatchers => [ qw(file screen) ], 
    371370      }; 
     
    383382              filename  => '/path/to/log', 
    384383              mode      => 'append', 
    385               'format'  => '[%d] [%p] %m at %F line %L%n', 
     384              format  => '[%d] [%p] %m at %F line %L%n', 
    386385          }; 
    387386      } 
     
    391390              min_level => 'info', 
    392391              stderr    => 1, 
    393               'format'  => '%m', 
     392              format  => '%m', 
    394393          }; 
    395394      } 
     
    463462 
    464463You can adjust package variable C<$Log::Dispatch::Config::CallerDepth> 
    465 to change the caller stack depth. The default value is 3, (which 
    466 depends heavily on Log::Dispatch's undocumented implementation. It 
    467 might be changed in future). 
     464to increase the caller stack depth. The default value is 0. 
    468465 
    469466  sub logit { 
    470467      my($class, $level, $msg) = @_; 
    471       local $Log::Dispatch::Config::CallerDepth = 4
     468      local $Log::Dispatch::Config::CallerDepth = 1
    472469      $Logger->$level($msg); 
    473470  } 
     471 
     472Note that your log caller's namespace should not begin with 
     473C</^Log::Dispatch/>, which makes this module confusing. 
    474474 
    475475=head1 AUTHOR 
  • Log-Dispatch-Config/trunk/lib/Log/Dispatch/Configurator/AppConfig.pm

    r379 r409  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.01
     5$VERSION = 0.02
    66 
     7use Log::Dispatch::Configurator; 
    78use base qw(Log::Dispatch::Configurator); 
    89use AppConfig; 
     
    2829    my $self = shift; 
    2930    return { 
    30         'format'    => scalar $self->_config->get('format'), 
     31        format      => scalar $self->_config->get('format'), 
    3132        dispatchers => [ split /\s+/, $self->_config->get('dispatchers') ], 
    3233    }; 
  • Log-Dispatch-Config/trunk/t/02_log.t

    r358 r409  
    3131 
    3232ok $err !~ qr/debug/, 'no debug'; 
    33 is $err, "alert", 'alert'; 
     33is $err, "alert %", 'alert %'; 
    3434 
    3535 
  • Log-Dispatch-Config/trunk/t/07_hardwired.t

    r379 r409  
    1313        my $self = shift; 
    1414        return { 
    15             'format' => undef, 
     15            format => undef, 
    1616            dispatchers => [ qw(file screen) ], 
    1717        }; 
     
    2626                filename  => 't/log.out', 
    2727                mode      => 'append', 
    28                 'format'  => '[%d] [%p] %m at %F line %L%n', 
     28                format    => '[%d] [%p] %m at %F line %L%n', 
    2929            }; 
    3030        } elsif ($name eq 'screen') { 
     
    3333                min_level => 'info', 
    3434                stderr    => 1, 
    35                 'format'  => '%m', 
     35                format    => '%m', 
    3636            }; 
    3737        } 
  • Log-Dispatch-Config/trunk/t/10_caller.t

    r388 r409  
    2121like slurp("t/log.out"), qr/foobar at .*10_caller\.t line 17/; 
    2222 
    23 local $Log::Dispatch::Config::CallerDepth = 4
     23local $Log::Dispatch::Config::CallerDepth = 1
    2424logit "bazbaz"; 
    2525like slurp("t/log.out"), qr/bazbaz at .*10_caller\.t line 24/; 
  • Log-Dispatch-Config/trunk/t/log.cfg

    r377 r409  
    1010screen.min_level = info 
    1111screen.stderr = 1 
    12 screen.format = %m 
     12screen.format = %m %% 
    1313