Procházet zdrojové kódy

Let is_debug see the level that log_init was given

log_init unpacked its arguments into a my $LEVEL of its own, which hid
the file-level $LEVEL that is_debug reads.  So is_debug fell back to
info whatever the configuration said, and the TOTP debugging in
Trog::Auth and the renderer's debug path could not be turned on.
Variables::ProhibitReusedNames found it.  log_init now takes $level and
sets $LEVEL from it.  The two //= defaults after the die were dead,
because the die needs both values to be true, and are gone.

The log file's size limit is written out as 10_485_760, for
ProhibitLiteralArithmetic, with a comment that says 10 MiB.

t/Trog-Log.t fails against the old log_init.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
troglodyne-bot před 6 dny
rodič
revize
622945832b
2 změnil soubory, kde provedl 30 přidání a 6 odebrání
  1. 4 6
      lib/Trog/Log.pm
  2. 26 0
      t/Trog-Log.t

+ 4 - 6
lib/Trog/Log.pm

@@ -80,13 +80,11 @@ Returns 1.
 =cut
 
 sub log_init {
-    my ( $LOGNAME, $LEVEL, $loggers ) = @_;
+    my ( $LOGNAME, $level, $loggers ) = @_;
 
-    die "Cannot initialize logs without log name and log level" unless $LOGNAME && $LEVEL;
-
-    $LOGNAME //= 'logs/tcms.log';
-    $LEVEL   //= 'info';
+    die "Cannot initialize logs without log name and log level" unless $LOGNAME && $level;
 
+    $LEVEL  = $level;
     $LOGDIR = dirname($LOGNAME);
 
     # By default only log requests & warnings.
@@ -96,7 +94,7 @@ sub log_init {
         filename  => $LOGNAME,
         min_level => $LEVEL,
         'mode'    => 'append',
-        size      => 10 * 1024 * 1024,
+        size      => 10_485_760,    # 10 MiB
         max       => 6,
     );
 

+ 26 - 0
t/Trog-Log.t

@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+use 5.040;
+use re '/aasx';
+use warnings FATAL => 'all';
+
+use Test::More;
+use Test::NoWarnings;
+use File::Temp qw{tempdir};
+
+use FindBin::libs;
+
+require_ok('Trog::Log') or BAIL_OUT("Can't find SUT");
+
+my $dir = tempdir( CLEANUP => 1 );
+
+subtest 'is_debug says which level log_init was given' => sub {
+    Trog::Log::log_init( "$dir/tcms.log", 'debug' );
+    ok( Trog::Log::is_debug(), 'debug is debug' );
+
+    Trog::Log::log_init( "$dir/tcms.log", 'info' );
+    ok( !Trog::Log::is_debug(), 'and info is not' );
+};
+
+Test::NoWarnings::had_no_warnings();
+
+done_testing();