Update per level log file writing and with level check
remove all non alphanumeric characters from the level string (debug call first parameter) so the file name is not invalid:wq
This commit is contained in:
@@ -6,6 +6,8 @@ namespace tests;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
// TODO: setLogPer test log file written matches pattern
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for Debug\Logging
|
* Test class for Debug\Logging
|
||||||
* @coversDefaultClass \CoreLibs\Debug\Logging
|
* @coversDefaultClass \CoreLibs\Debug\Logging
|
||||||
|
|||||||
@@ -175,6 +175,12 @@ print "GETCALLERCLASS(NON CLASS): " . \CoreLibs\Debug\Support::getCallerClass()
|
|||||||
print "S::FSETFILENAME: " . FileWriter::fsetFilename('class_test_debug_file.log') . "<br>";
|
print "S::FSETFILENAME: " . FileWriter::fsetFilename('class_test_debug_file.log') . "<br>";
|
||||||
print "S::FDEBUG: " . FileWriter::fdebug('CLASS TEST DEBUG FILE: ' . date('Y-m-d H:i:s')) . "<br>";
|
print "S::FDEBUG: " . FileWriter::fdebug('CLASS TEST DEBUG FILE: ' . date('Y-m-d H:i:s')) . "<br>";
|
||||||
|
|
||||||
|
// test per level
|
||||||
|
$debug->setLogPer('level', true);
|
||||||
|
$debug->debug('TEST PER LEVEL', 'Per level test');
|
||||||
|
$debug->debug('()', 'Per level test: invalid chars');
|
||||||
|
$debug->setLogPer('level', false);
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
// future DEPRECATED
|
// future DEPRECATED
|
||||||
// $debug->debug('BASIC CLASS', 'Debug test');
|
// $debug->debug('BASIC CLASS', 'Debug test');
|
||||||
|
|||||||
@@ -365,7 +365,18 @@ class Logging
|
|||||||
}
|
}
|
||||||
$fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename
|
$fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename
|
||||||
|
|
||||||
$rpl_string = !$this->log_per_level ? '' : '_' . $level; // if request to write to one file
|
// write per level
|
||||||
|
$rpl_string = !$this->log_per_level ? '' :
|
||||||
|
// normalize level, replace all non alphanumeric characters with -
|
||||||
|
'_' . (
|
||||||
|
// if return is only - then set error string
|
||||||
|
preg_match(
|
||||||
|
"/^-+$/",
|
||||||
|
$level_string = preg_replace("/[^A-Za-z0-9-_]/", '-', $level) ?? ''
|
||||||
|
) ?
|
||||||
|
'INVALID-LEVEL-STRING' :
|
||||||
|
$level_string
|
||||||
|
);
|
||||||
$fn = str_replace('##LEVEL##', $rpl_string, $fn); // create output filename
|
$fn = str_replace('##LEVEL##', $rpl_string, $fn); // create output filename
|
||||||
// set per class, but don't use get_class as we will only get self
|
// set per class, but don't use get_class as we will only get self
|
||||||
$rpl_string = !$this->log_per_class ? '' : '_'
|
$rpl_string = !$this->log_per_class ? '' : '_'
|
||||||
|
|||||||
Reference in New Issue
Block a user