| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 38 | 0 | $effective_level = $level; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | ▶ | elsif (defined $debug && $debug) { | |||||||||||||||||||||||||||
|
Condition33%1/3
defined $debug and $debug
MC/DC0%0/2
defined $debug and $debug
defined $debug
$debug
Truth table33%1/3
A and B
A= defined $debugB= $debug
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $effective_level = $debug > 1 ? 'trace' : 'debug'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 12 | require Log::Any::Adapter; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 12 | ▶ | if ($output && $output ne 'stderr') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$output and $output ne "stderr"
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"
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($output eq 'stdout') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$category //= scalar caller
$category
Truth table100%2/2
A
A= $category
| |||||||||||||||||||||||||||||
| 85 | 2 | return Log::Any->get_logger(category => $category); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 12 | 1; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||