loglib/tests/logging.php
Netkas 951bdb325e
"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."
2023-10-12 23:40:05 -04:00

74 lines
No EOL
2.5 KiB
PHP

<?php
use LogLib\Log;
use LogLib\Objects\Options;
require('ncc');
import('net.nosial.loglib', 'latest');
$options = new Options('net.nosial.optslib');
Log::register($options);
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');
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();