Agent/Logger.pm

filter: Statementstmt 81.2% 39 / 48 Branchbran 37.5% 6 / 16 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 88.8% 8 / 9 Podpod 100% 1 / 1 totaltotal 67.8% 59 / 87 CC 13 SCAR 21.4
CC
13
Cov
68%
_setup_default_adapter
17.7
_format_message
6.0
import
4.0
CRAP 8.5
« Agent/Options.pm ↑ Summary Agent/Hook/Registry.pm »
1 package Claude::Agent::Logger;
2  
3 12 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use Log::Any ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 my $_adapter_configured = 0;
10  
11 40 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
12 40 my ($class, @args) = @_;
13 40 my $caller = caller;
14  
15 40 ▶ unless ($_adapter_configured) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_adapter_configured) 12 28 40
16 12 $_adapter_configured = 1;
17 12 _setup_default_adapter();
18 }
19  
20 40 for my $arg (@args) {
21 39 ▶ if ($arg eq '$log') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "\$log") 39 0 39
22 39 my $logger = Log::Any->get_logger(category => $caller);
23 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 39 *{"${caller}::log"} = \$logger;
25 }
26 }
27  
28 40 return;
29 }
30  
31 12 ▶sub _setup_default_adapter {
Subroutine _setup_default_adapter: called CC=8 SCAR=28.7
32 12 my $level = $ENV{CLAUDE_AGENT_LOG_LEVEL};
33 12 my $output = $ENV{CLAUDE_AGENT_LOG_OUTPUT};
34 12 my $debug = $ENV{CLAUDE_AGENT_DEBUG};
35  
36 12 my $effective_level = 'warning';
37 12 ▶ if ($level) {
Branch: 2 branches
BranchTrueFalseTotal
if ($level) { } 0 12 12
elsif (defined $debug and $debug) { } 0 24 24
38 0 $effective_level = $level;
39 }
40 ▶ elsif (defined $debug && $debug) {
Condition33%1/3
defined $debug and $debug
!ll&&!rl&&r
1200
MC/DC0%0/2
defined $debug and $debug
defined $debug $debug
Truth table33%1/3
A and B
A= defined $debugB= $debug
ABresult
0X0
100
111
41 0 ▶ $effective_level = $debug > 1 ? 'trace' : 'debug';
Branch: 1 branch
BranchTrueFalseTotal
$debug > 1 ? : 0 0 0
42 }
43  
44 12 require Log::Any::Adapter;
45  
46 12 ▶ if ($output && $output ne 'stderr') {
Branch: 1 branch
BranchTrueFalseTotal
if ($output and $output ne 'stderr') { } 0 12 12
Condition33%1/3
$output and $output ne "stderr"
!ll&&!rl&&r
1200
MC/DC0%0/2
$output and $output ne "stderr"
$output $output ne "stderr"
Truth table33%1/3
A and B
A= $outputB= $output ne "stderr"
ABresult
0X0
100
111
47 0 ▶ if ($output eq 'stdout') {
Branch: 1 branch
BranchTrueFalseTotal
if ($output eq 'stdout') { } 0 0 0
48 0 Log::Any::Adapter->set(
49 { formatter => \&_format_message },
50 'Stdout',
51 log_level => $effective_level,
52 );
53 }
54 else {
55 0 Log::Any::Adapter->set(
56 { formatter => \&_format_message },
57 'File',
58 $output,
59 log_level => $effective_level,
60 );
61 }
62 }
63 else {
64 12 Log::Any::Adapter->set(
65 { formatter => \&_format_message },
66 'Stderr',
67 log_level => $effective_level,
68 );
69 }
70  
71 12 return;
72 }
73  
74 0 ▶sub _format_message {
Subroutine _format_message: not called CC=2 SCAR=17.9
75 0 my ($category, $level, $message, @args) = @_;
76 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
77 0 $message = sprintf($message, @args);
78 }
79 0 return $message;
80 }
81  
82 2 ▶sub get_logger {
Subroutine get_logger: called CC=2 SCAR=6.9
Pod documented
83 2 my ($category) = @_;
84 2 ▶ $category //= scalar caller;
Condition100%2/2
$category //= scalar caller
l!l
11
MC/DC100%1/1
$category //= scalar caller
$category
Truth table100%2/2
A
A= $category
Aresult
11
00
85 2 return Log::Any->get_logger(category => $category);
86 }
87  
88  
89 12 1;
90  
91 __END__
« Agent/Options.pm ↑ Summary Agent/Hook/Registry.pm »