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