File Coverage

blib/lib/Log/Log4perl/Appender/TAP.pm
Criterion Covered Total %
statement 25 25 100.0
branch n/a
condition 3 5 60.0
subroutine 7 7 100.0
pod 1 2 50.0
total 36 39 92.3


line stmt bran cond sub pod time code
1             package Log::Log4perl::Appender::TAP;
2              
3 1     1   531912 use strict;
  1         2  
  1         31  
4 1     1   7 use warnings;
  1         2  
  1         36  
5 1     1   12 use 5.008001;
  1         4  
6 1     1   3 use Test2::API qw( context );
  1         2  
  1         47  
7 1     1   15 use parent qw( Log::Log4perl::Appender );
  1         1  
  1         6  
8              
9             # ABSTRACT: Append to TAP output
10             our $VERSION = '0.07'; # VERSION
11              
12              
13             sub new
14             {
15 3     3 1 2802 my $proto = shift;
16 3   33     14 my $class = ref $proto || $proto;
17 3         9 my %args = @_;
18             bless {
19 3   100     19 method => $args{method} || 'note',
20             }, $class;
21             }
22              
23             sub log
24             {
25 2     2 0 43395 my $self = shift;
26 2         7 my %args = @_;
27 2         8 my $method = $self->{method};
28 2         6 my $ctx = context();
29 2         139 $ctx->$method($args{message});
30 2         449 $ctx->release;
31 2         60 return;
32             }
33              
34             1;
35              
36             __END__
37              
38             =pod
39              
40             =encoding UTF-8
41              
42             =head1 NAME
43              
44             Log::Log4perl::Appender::TAP - Append to TAP output
45              
46             =head1 VERSION
47              
48             version 0.07
49              
50             =head1 SYNOPSIS
51              
52             use Test2::V0;
53             use Log::Log4perl qw( :easy );
54            
55             Log::Log4perl::init(\<<CONF);
56             log4perl.rootLogger=ERROR, TAP
57             log4perl.appender.TAP=Log::Log4perl::Appender::TAP
58             log4perl.appender.TAP.method=diag
59             log4perl.appender.TAP.layout=PatternLayout
60             log4perl.appender.TAP.layout.ConversionPattern="[%rms] %m"
61             CONF
62            
63             DEBUG "this message doesn't see the light of day";
64             ERROR "This gets logged to TAP using diag";
65            
66             ok 1;
67            
68             done_testing;
69              
70             outputs:
71              
72             # Seeded srand with seed '20250911' from local date.
73             # "[0ms] This gets logged to TAP using diag"
74             ok 1
75             1..1
76              
77             =head1 DESCRIPTION
78              
79             This very simple L<Log::Log4perl> appender sends log output via L<Test2::API> to TAP
80             (or any other format supported by L<Test2::API>). It also works with
81             L<Test::Builder> and L<Test::More> so long as you have L<Test2::API>
82             installed. It only takes one special argument, the method, which can
83             be either C<diag> or C<note>.
84              
85             =head1 SEE ALSO
86              
87             =over 4
88              
89             =item L<Log::Log4perl>
90              
91             Main module documentation for C<Log4perl>.
92              
93             =item L<Log::Dispatch::TAP>
94              
95             Similar module but for L<Log::Dispatch> instead of C<Log4perl>.
96              
97             =back
98              
99             =head1 AUTHOR
100              
101             Graham Ollis <plicease@cpan.org>
102              
103             =head1 COPYRIGHT AND LICENSE
104              
105             This software is copyright (c) 2017-2025 by Graham Ollis.
106              
107             This is free software; you can redistribute it and/or modify it under
108             the same terms as the Perl 5 programming language system itself.
109              
110             =cut