"Refactor logging logic to improve log level and backtrace information

The code has been updated to enhance the way log levels and backtrace information is handled. Changes have been done to ensure the backtrace ignores any calls coming from the LogLib namespace, improving clarity and reducing noise in the log output. Additionally, changes were made to 'colorize' and 'log' methods to adjust the typing of the log level from string to integer, enhancing the consistency of log level usage throughout the code. Removed the Backtrace class that was not serving any purpose after these updates. Tests are also updated to ensure proper functionality."
This commit is contained in:
Netkas 2023-10-12 23:40:05 -04:00
parent 7f2332e228
commit 951bdb325e
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
7 changed files with 157 additions and 228 deletions

View file

@ -1,6 +1,5 @@
<?php
use LogLib\Abstracts\LevelType;
use LogLib\Log;
use LogLib\Objects\Options;
@ -15,4 +14,61 @@
Log::info('net.nosial.optslib', 'This is an info message');
Log::warning('net.nosial.optslib', 'This is a warning message');
Log::error('net.nosial.optslib', 'This is an error message');
Log::fatal('net.nosial.optslib', 'This is a fatal message');
Log::fatal('net.nosial.optslib', 'This is a fatal message');
class test
{
public function testLogging(): void
{
Log::debug('net.nosial.optslib', 'This is a debug message');
Log::verbose('net.nosial.optslib', 'This is a verbose message');
Log::info('net.nosial.optslib', 'This is an info message');
Log::warning('net.nosial.optslib', 'This is a warning message');
Log::error('net.nosial.optslib', 'This is an error message');
Log::fatal('net.nosial.optslib', 'This is a fatal message');
}
}
$test = new test();
$test->testLogging();
eval('\LogLib\Log::debug(\'net.nosial.optslib\', \'This is a debug message\');');
eval('\LogLib\Log::verbose(\'net.nosial.optslib\', \'This is a verbose message\');');
$callable = static function()
{
Log::info('net.nosial.optslib', 'This is an info message');
Log::warning('net.nosial.optslib', 'This is a warning message');
Log::error('net.nosial.optslib', 'This is an error message');
Log::fatal('net.nosial.optslib', 'This is a fatal message');
};
$callable();
class test2
{
public function testEval(): void
{
eval('\LogLib\Log::debug(\'net.nosial.optslib\', \'This is a debug message\');');
eval('\LogLib\Log::verbose(\'net.nosial.optslib\', \'This is a verbose message\');');
}
public function testCallable(): void
{
$b = static function()
{
Log::info('net.nosial.optslib', 'This is an info message');
Log::warning('net.nosial.optslib', 'This is a warning message');
Log::error('net.nosial.optslib', 'This is an error message');
Log::fatal('net.nosial.optslib', 'This is a fatal message');
};
$b();
}
}
$test2 = new test2();
$test2->testEval();
$test2->testCallable();