Skip to content

Commit e1cfc50

Browse files
chore: only check log level once
1 parent 3ba673f commit e1cfc50

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/BaseTraits.inc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use function RESTAPI\Core\Tools\get_classes_from_namespace;
1111
* automatically inherit all resources included.
1212
*/
1313
trait BaseTraits {
14+
private static int $__log_level;
15+
1416
/**
1517
* Obtains the shortname of the called class.
1618
* @return string The shortname for this object's class.
@@ -42,12 +44,20 @@ trait BaseTraits {
4244
* @param string $logfile The log file to write to. This must be a valid logging facility defined in the package's
4345
* info.xml file.
4446
*/
45-
public function log(int $level, string $message, string $logfile = 'restapi'): void {
46-
# Get the log level limit from the RESTAPI settings
47-
$log_limit = constant(RESTAPISettings::get_pkg_config()['log_level']) ?? 4;
47+
public static function log(int $level, string $message, string $logfile = 'restapi'): void {
48+
# If this is a system log, use the pfSense 'log_error' function instead
49+
if ($logfile === 'system') {
50+
log_error($message);
51+
return;
52+
}
53+
54+
# If the log level has not been set yet, obtain it
55+
if (!isset(self::$__log_level)) {
56+
self::$__log_level = constant(RESTAPISettings::get_pkg_config()['log_level']) ?? 4;
57+
}
4858

4959
# Do not log if the incoming level is higher than the configured log level
50-
if ($level >= $log_limit) {
60+
if ($level > self::$__log_level) {
5161
return;
5262
}
5363

0 commit comments

Comments
 (0)