From 0b93f9f146c7271c14e936e3b84261e037b710e2 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 1 Jun 2023 08:40:55 +0900 Subject: [PATCH] Bug fixes and minor updates - Removed echo from Support Debug dumpVar call - deprecated DB\IO toggle dbDebug and changed set/get to be like normal ones where set just sets and doesn't return anything - Renamed the logJsDebug to loggingLevelIsDebug (other levels can be checked with ->getLoggingLevel()->includes(Level::...)) Adjusted tests for all changes --- 4dev/tests/DB/CoreLibsDBIOTest.php | 92 +++++-------------- .../Logging/CoreLibsLoggingLoggingTest.php | 10 +- www/admin/class_test.logging.php | 15 ++- www/includes/admin_header.php | 2 +- www/lib/CoreLibs/DB/IO.php | 16 ++-- www/lib/CoreLibs/Debug/Support.php | 1 - www/lib/CoreLibs/Logging/Logging.php | 6 +- 7 files changed, 54 insertions(+), 88 deletions(-) diff --git a/4dev/tests/DB/CoreLibsDBIOTest.php b/4dev/tests/DB/CoreLibsDBIOTest.php index 0ad119a4..bd145ffb 100644 --- a/4dev/tests/DB/CoreLibsDBIOTest.php +++ b/4dev/tests/DB/CoreLibsDBIOTest.php @@ -99,7 +99,6 @@ final class CoreLibsDBIOTest extends TestCase ], ]; private static $log; - private static bool $db_debug = false; /** * Test if pgsql module loaded @@ -123,7 +122,6 @@ final class CoreLibsDBIOTest extends TestCase 'log_file_id' => 'CoreLibs-DB-IO-Test', ]); // will be true, default logging is true - self::$db_debug = self::$log->getLoggingLevel()->includes(Level::Debug); $db = new \CoreLibs\DB\IO( self::$db_config['valid'], self::$log @@ -521,6 +519,9 @@ final class CoreLibsDBIOTest extends TestCase */ public function debugSetProvider(): array { + // 0: db connecdtion + // 1: override log flag, null for default + // 2: set flag return [ 'default debug set' => [ // what base connection @@ -538,95 +539,46 @@ final class CoreLibsDBIOTest extends TestCase ]; } - /** - * test set for toggleDEbug - * - * @return array - */ - public function debugToggleProvider(): array - { - return [ - 'default debug set' => [ - // what base connection - 'valid', - // actions - null, - // toggle is inverse - self::$db_debug ? true : false, - ], - 'toggle debug to false' => [ - 'valid', - false, - false, - ] - ]; - } - /** * Test dbSetDbug, dbGetDebug * * @covers ::dbGetDbug * @covers ::dbSetDebug - * @dataProvider debugSetProvider - * @testdox Setting debug $set will be $expected [$_dataName] + * @testdox Set and Get Debug flag * * @return void */ - public function testDbSetDebug( - string $connection, - ?bool $set, - bool $expected - ): void { + public function testDbSetDebug(): void + { + $connection = 'valid'; + // default set, expect true $db = new \CoreLibs\DB\IO( self::$db_config[$connection], self::$log ); - echo "Expected: " . self::$db_debug . "\n"; - $this->assertEquals( - $expected, - $set === null ? - $db->dbSetDebug() : - $db->dbSetDebug($set) + $this->assertTrue( + $db->dbGetDebug() ); - // must always match - $this->assertEquals( - $expected, + // switch off + $db->dbSetDebug(false); + $this->assertFalse( $db->dbGetDebug() ); $db->dbClose(); - } - - /** - * Test dbToggleDebug, dbGetDebug - * - * @covers ::dbGetDbug - * @covers ::dbSetDebug - * @dataProvider debugToggleProvider - * @testdox Toggle debug $toggle will be $expected [$_dataName] - * - * @return void - */ - public function testDbToggleDebug( - string $connection, - ?bool $toggle, - bool $expected - ): void { + // second conenction with log set NOT debug + $log = new \CoreLibs\Logging\Logging([ + // 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log', + 'log_folder' => DIRECTORY_SEPARATOR . 'tmp', + 'log_file_id' => 'CoreLibs-DB-IO-Test', + 'log_level' => \CoreLibs\Logging\Logger\Level::Notice, + ]); $db = new \CoreLibs\DB\IO( self::$db_config[$connection], - self::$log + $log ); - $this->assertEquals( - $expected, - $toggle === null ? - $db->dbToggleDebug() : - $db->dbToggleDebug($toggle) - ); - // must always match - $this->assertEquals( - $expected, + $this->assertFalse( $db->dbGetDebug() ); - $db->dbClose(); } // - set max query call sets diff --git a/4dev/tests/Logging/CoreLibsLoggingLoggingTest.php b/4dev/tests/Logging/CoreLibsLoggingLoggingTest.php index fd75ebdd..177545bc 100644 --- a/4dev/tests/Logging/CoreLibsLoggingLoggingTest.php +++ b/4dev/tests/Logging/CoreLibsLoggingLoggingTest.php @@ -217,14 +217,14 @@ final class CoreLibsLoggingLoggingTest extends TestCase // setLoggingLevel // getLoggingLevel - // getJsDebug + // loggingLevelIsDebug /** * Undocumented function * * @covers ::setLoggingLevel * @covers ::getLoggingLevel - * @covers ::getJsDebug + * @covers ::loggingLevelIsDebug * @testdox setLoggingLevel set/get checks * * @return void @@ -242,7 +242,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase $log->getLoggingLevel() ); $this->assertFalse( - $log->getJsDebug() + $log->loggingLevelIsDebug() ); // not set, should be debug] $log = new \CoreLibs\Logging\Logging([ @@ -254,7 +254,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase $log->getLoggingLevel() ); $this->assertTrue( - $log->getJsDebug() + $log->loggingLevelIsDebug() ); // invalid, should be debug, will throw excpetion too $this->expectException(\InvalidArgumentException::class); @@ -269,7 +269,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase $log->getLoggingLevel() ); $this->assertTrue( - $log->getJsDebug() + $log->loggingLevelIsDebug() ); // set valid, then change $log = new \CoreLibs\Logging\Logging([ diff --git a/www/admin/class_test.logging.php b/www/admin/class_test.logging.php index 7ac13765..d93f8f01 100644 --- a/www/admin/class_test.logging.php +++ b/www/admin/class_test.logging.php @@ -23,6 +23,8 @@ ob_end_flush(); $ECHO_ALL = true; // use CoreLibs\Debug\Support; + +use CoreLibs\Debug\Support; use CoreLibs\Logging\Logger\Level; use CoreLibs\Logging\Logger\Flag; // use CoreLibs\Debug\Support; @@ -51,7 +53,18 @@ print "Flag: per_run ->value: " . Flag::per_class->value . "
"; $log->setLogUniqueId(); print "LogUniqId: " . $log->getLogUniqueId() . "
"; -print "DUMP: " . $log->dV(['something' => 'error']) . "
"; +print "Is Debug (check): " . Support::printBool($log->getLoggingLevel()->includes( + Level::Debug +)) . "
"; +print "Is Debug (fk): " . Support::printBool($log->loggingLevelIsDebug()) . "
"; +$log->setLoggingLevel(Level::Notice); +print "Is Debug (check): " . Support::printBool($log->getLoggingLevel()->includes( + Level::Debug +)) . "
"; +print "Is Debug (fk): " . Support::printBool($log->loggingLevelIsDebug()) . "
"; +$log->setLoggingLevel(Level::Debug); + +print "DUMP:
" . $log->dV(['something' => 'error']) . "

"; $log->debug('LEGACY', 'Some legacy shit here'); $log->debug('ARRAY', 'Dump some data: ' . $log->dV(['something' => 'error'])); diff --git a/www/includes/admin_header.php b/www/includes/admin_header.php index 6c920790..edd6381e 100644 --- a/www/includes/admin_header.php +++ b/www/includes/admin_header.php @@ -121,6 +121,6 @@ if (!$login->loginActionRun()) { //------------------------------ logging end // pass on DEBUG flag to JS via smarty variable -$smarty->DATA['JS_DEBUG'] = $log->getJsDebug(); +$smarty->DATA['JS_DEBUG'] = $log->loggingLevelIsDebug(); // __END__ diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index e890ea1b..a3837104 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -3123,16 +3123,13 @@ class IO /** * switches the debug flag on or off - * if none given, then return current set only - * @param bool|null $debug true/false or null for just getting current set - * @return bool Current debug flag as set + * + * @param bool $debug True/False to turn debugging in this calss on or off + * @return void */ - public function dbSetDebug(?bool $debug = null): bool + public function dbSetDebug(bool $debug): void { - if ($debug !== null) { - $this->db_debug = $debug; - } - return $this->db_debug; + $this->db_debug = $debug; } /** @@ -3140,9 +3137,11 @@ class IO * OR * with the optional parameter fix sets debug * returns current set stats + * * @param bool|null $debug Flag to turn debug on off or null for toggle * @return bool Current debug status * True for debug is on, False for off + * @deprecated Use dbSetDebug and dbGetDebug */ public function dbToggleDebug(?bool $debug = null): bool { @@ -3156,6 +3155,7 @@ class IO /** * Return current set db debug flag status + * * @return bool Current debug status */ public function dbGetDebug(): bool diff --git a/www/lib/CoreLibs/Debug/Support.php b/www/lib/CoreLibs/Debug/Support.php index ef492c02..15cdb7af 100644 --- a/www/lib/CoreLibs/Debug/Support.php +++ b/www/lib/CoreLibs/Debug/Support.php @@ -177,7 +177,6 @@ class Support $caller_level = 1; $caller_list = self::getCallerMethodList(); if ($caller_list[0] == 'dV') { - echo "Raise caller level
: " . $caller_list[0] . "
"; $caller_level = 2; } // we need to strip the string in log_level === Level::Debug ? true : false; + return $this->getLoggingLevel()->includes( + Level::Debug + ); } // log file id set (file name prefix)