home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Screen.pm < prev    next >
Encoding:
Perl POD Document  |  2003-09-27  |  2.9 KB  |  132 lines

  1. package Log::Dispatch::Screen;
  2.  
  3. use strict;
  4.  
  5. use Log::Dispatch::Output;
  6.  
  7. use base qw( Log::Dispatch::Output );
  8.  
  9. use Params::Validate qw(validate BOOLEAN);
  10. Params::Validate::validation_options( allow_extra => 1 );
  11.  
  12. use vars qw[ $VERSION ];
  13.  
  14. $VERSION = sprintf "%d.%02d", q$Revision: 1.17 $ =~ /: (\d+)\.(\d+)/;
  15.  
  16. 1;
  17.  
  18. sub new
  19. {
  20.     my $proto = shift;
  21.     my $class = ref $proto || $proto;
  22.  
  23.     my %p = validate( @_, { stderr => { type => BOOLEAN,
  24.                     default => 1 },
  25.               } );
  26.  
  27.     my $self = bless {}, $class;
  28.  
  29.     $self->_basic_init(%p);
  30.     $self->{stderr} = exists $p{stderr} ? $p{stderr} : 1;
  31.  
  32.     return $self;
  33. }
  34.  
  35. sub log_message
  36. {
  37.     my $self = shift;
  38.     my %p = @_;
  39.  
  40.     if ($self->{stderr})
  41.     {
  42.     print STDERR $p{message};
  43.     }
  44.     else
  45.     {
  46.     print STDOUT $p{message};
  47.     }
  48. }
  49.  
  50. __END__
  51.  
  52. =head1 NAME
  53.  
  54. Log::Dispatch::Screen - Object for logging to the screen
  55.  
  56. =head1 SYNOPSIS
  57.  
  58.   use Log::Dispatch::Screen;
  59.  
  60.   my $screen = Log::Dispatch::Screen->new( name      => 'screen',
  61.                                            min_level => 'debug',
  62.                                            stderr    => 1 );
  63.  
  64.   $screen->log( level => 'alert', message => "I'm searching the city for sci-fi wasabi\n" );
  65.  
  66. =head1 DESCRIPTION
  67.  
  68. This module provides an object for logging to the screen (really
  69. STDOUT or STDERR).
  70.  
  71. =head1 METHODS
  72.  
  73. =over 4
  74.  
  75. =item * new(%p)
  76.  
  77. This method takes a hash of parameters.  The following options are
  78. valid:
  79.  
  80. =over 8
  81.  
  82. =item * name ($)
  83.  
  84. The name of the object (not the filename!).  Required.
  85.  
  86. =item * min_level ($)
  87.  
  88. The minimum logging level this object will accept.  See the
  89. Log::Dispatch documentation for more information.  Required.
  90.  
  91. =item * max_level ($)
  92.  
  93. The maximum logging level this obejct will accept.  See the
  94. Log::Dispatch documentation for more information.  This is not
  95. required.  By default the maximum is the highest possible level (which
  96. means functionally that the object has no maximum).
  97.  
  98. =item * stderr (0 or 1)
  99.  
  100. Indicates whether or not logging information should go to STDERR.  If
  101. false, logging information is printed to STDOUT instead.  This
  102. defaults to true.
  103.  
  104. =item * callbacks( \& or [ \&, \&, ... ] )
  105.  
  106. This parameter may be a single subroutine reference or an array
  107. reference of subroutine references.  These callbacks will be called in
  108. the order they are given and passed a hash containing the following keys:
  109.  
  110.  ( message => $log_message, level => $log_level )
  111.  
  112. The callbacks are expected to modify the message and then return a
  113. single scalar containing that modified message.  These callbacks will
  114. be called when either the C<log> or C<log_to> methods are called and
  115. will only be applied to a given message once.
  116.  
  117. =back
  118.  
  119. =item * log_message( message => $ )
  120.  
  121. Sends a message to the appropriate output.  Generally this shouldn't
  122. be called directly but should be called through the C<log()> method
  123. (in Log::Dispatch::Output).
  124.  
  125. =back
  126.  
  127. =head1 AUTHOR
  128.  
  129. Dave Rolsky, <autarch@urth.org>
  130.  
  131. =cut
  132.