Count/Log.pm

filter: Statementstmt 100% 54 / 54 Branchbran 100% 10 / 10 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 12 / 12 Podpod 25.0% 1 / 4 totaltotal 96.5% 83 / 86 CC 8 SCAR 7.7
CC
8
Cov
100%
_logsetup
4.0
logd
3.0
logt
2.0
CRAP 2.2
« Count/Common.pm ↑ Summary Count/Method/CondorcetIRV.pm »
1 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 25 ▶use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 25 ▶use feature qw /postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package Vote::Count::Log;
8 25 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 25 ▶no warnings 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 25 ▶use Path::Tiny 0.108;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 25 our $VERSION='1.10';
14  
15 =head1 NAME
16  
17 Vote::Count::Log
18  
19 =head1 VERSION 1.10
20  
21 =cut
22  
23 # ABSTRACT: Logging for Vote::Count. Toolkit for vote counting.
24  
25 =head1 Vote::Count Logging Methods
26  
27 =head2 LogTo
28  
29 Sets a path and Naming pattern for writing logs with the WriteLogs method.
30  
31 'LogTo' => '/logging_path/election_name'
32  
33 LogTo will not create a new directory if the directory does not exist.
34  
35 The default log location is '/tmp/votecount'.
36  
37 =head2 LogPath
38  
39 Specifies a Path to the Log Files, unlike LogTo, LogPath will create the Path if it does not exist.
40  
41 =head2 LogBaseName
42  
43 Sets the Base portion of the logfile names, but only if LogPath is specified. The default value is votecount.
44  
45 =head2 WriteLog
46  
47 Write the logs appending '.brief', '.full', and '.debug' for the three logs where brief is a summary written with the logt (log terse) method, the full transcript log written with logv, and finally the debug log written with logd. Each higher log level captures all events of the lower log levels.
48  
49 =head1 Logging Events
50  
51 When logging from your methods, use logt for events that produce a summary, use logv for events that should be in the full transcript such as round counts, and finally debug is for events that may be helpful in debugging but which should not be in the transcript. Events written to logt will be included in the verbose log and all events in the verbose log will be in the debug log.
52  
53 =head1 Debug Flag
54  
55 When the debug flag is logx methods will also emit the event as a warning (STDERR). The Debug Flag defaults to off (0), but can be explicitly set via the new method of a Vote::Count object, or toggled by passing 0 or 1 via the Debug Method.
56  
57 $Election->Debug(1); # turn debug on
58 is( $Election->Action(), $expected, 'Thing Im debugging');
59 $Election->Debug(0); # turn debug off
60  
61 =cut
62  
63 25 has 'LogTo' => (
64 is => 'lazy',
65 is => 'rw',
66 isa => 'Str',
67 builder => '_logsetup',
68 );
69  
70 25 has 'LogPath' => (
71 is => 'rw',
72 isa => 'Str',
73 default => '/tmp',
74 );
75  
76 25 has 'LogBaseName' => (
77 is => 'rw',
78 isa => 'Str',
79 default => 'votecount'
80 );
81  
82 25 has 'Debug' => (
83 default => 0,
84 is => 'rw',
85 isa => 'Bool',
86 );
87  
88 ▶sub _logsetup ( $self ) {
Subroutine _logsetup: called CC=4 SCAR=13.9
89 119 ▶ my $pathBase = $self->{'LogPath'} || '/tmp';
Condition100%2/2
$self->{'LogPath'} || '/tmp'
l!l
8930
MC/DC100%1/1
$self->{'LogPath'} || '/tmp'
$self->{'LogPath'}
Truth table100%2/2
A
A= $self->{'LogPath'}
Aresult
11
00
90 119 $pathBase =~ s/\/$|\\$//; # trim \ or / from end.
91 119 ▶ unless ( stat $pathBase ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stat $pathBase) 1 118 119
92 1 path($pathBase)->mkpath();
93 }
94 119 ▶ my $baseName = $self->{'LogBaseName'} || 'votecount';
Condition100%2/2
$self->{'LogBaseName'} || 'votecount'
l!l
9029
MC/DC100%1/1
$self->{'LogBaseName'} || 'votecount'
$self->{'LogBaseName'}
Truth table100%2/2
A
A= $self->{'LogBaseName'}
Aresult
11
00
95 119 return "$pathBase/$baseName";
96 }
97  
98 sub logt {
99 359 ▶ my $self = shift @_;
Subroutine logt: called CC=2 SCAR=6.9
Pod undocumented
100 359 ▶ return $self->{'LogT'} unless (@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 23 336 359
101 336 my $msg = join( "\n", @_ ) . "\n";
102 336 $self->{'LogT'} .= $msg;
103 336 $self->{'LogV'} .= $msg;
104 336 $self->logd(@_);
105 }
106  
107 sub logv {
108 5485 ▶ my $self = shift @_;
Subroutine logv: called CC=2 SCAR=6.9
Pod undocumented
109 5485 ▶ return $self->{'LogV'} unless (@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 26 5459 5485
110 5459 my $msg = join( "\n", @_ ) . "\n";
111 5459 $self->{'LogV'} .= $msg;
112 5459 $self->logd(@_);
113 }
114  
115 sub logd {
116 5854 ▶ my $self = shift @_;
Subroutine logd: called CC=3 SCAR=11.0
Pod undocumented
117 5854 ▶ return $self->{'LogD'} unless (@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 21 5833 5854
118 5833 my @args = (@_);
119 # since ops are seqential and fast logging event times
120 # clutters the debug log.
121 # unshift @args, localtime->date . ' ' . localtime->time;
122 5833 my $msg = join( "\n", @args ) . "\n";
123 5833 $self->{'LogD'} .= $msg;
124 5833 ▶ warn $msg if $self->Debug();
Branch: 1 branch
BranchTrueFalseTotal
if $self->Debug 1 5832 5833
125 }
126  
127 sub WriteLog {
128 12 ▶ my $self = shift @_;
Subroutine WriteLog: called CC=1 SCAR=0.0
Pod documented
129 12 my $logroot = $self->LogTo();
130 12 path("$logroot.brief")->spew( $self->logt() );
131 12 path("$logroot.full")->spew( $self->logv() );
132 12 path("$logroot.debug")->spew( $self->logd() );
133 }
134  
135 25 1;
136  
137 #FOOTER
138  
139 =pod
140  
141 BUG TRACKER
142  
143 L<https://github.com/brainbuz/Vote-Count/issues>
144  
145 AUTHOR
146  
147 John Karr (BRAINBUZ) brainbuz@cpan.org
148  
149 CONTRIBUTORS
150  
151 Copyright 2019 by John Karr (BRAINBUZ) brainbuz@cpan.org.
152  
153 LICENSE
154  
155 This module is released under the GNU Public License Version 3. See license file for details. For more information on this license visit L<http://fsf.org>.
156  
157 =cut
158  
« Count/Common.pm ↑ Summary Count/Method/CondorcetIRV.pm »