File tree Expand file tree Collapse file tree
pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ use function RESTAPI\Core\Tools\get_classes_from_namespace;
1111 * automatically inherit all resources included.
1212 */
1313trait 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
You can’t perform that action at this time.
0 commit comments