Skip to content

Commit 80e4950

Browse files
refactor: use string representation for log levels
1 parent 5ab8e56 commit 80e4950

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ trait BaseTraits {
4444
*/
4545
public function log(int $level, string $message, string $logfile = 'restapi'): void {
4646
# Get the log level limit from the RESTAPI settings
47-
$log_limit = (int) RESTAPISettings::get_pkg_config()['log_level'] ?? 3;
47+
$log_limit = constant(RESTAPISettings::get_pkg_config()['log_level']) ?? 4;
4848

4949
# Do not log if the incoming level is higher than the configured log level
5050
if ($level >= $log_limit) {

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/RESTAPISettings.inc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RESTAPISettings extends Model {
3131
public BooleanField $keep_backup;
3232
public BooleanField $login_protection;
3333
public BooleanField $log_successful_auth;
34-
public IntegerField $log_level;
34+
public StringField $log_level;
3535
public BooleanField $allow_pre_releases;
3636
public BooleanField $hateoas;
3737
public BooleanField $expose_sensitive_fields;
@@ -94,21 +94,21 @@ class RESTAPISettings extends Model {
9494
failed API authentication attempts are logged to prevent flooding the authentication logs. This field is
9595
only applicable when the API `login_protection` setting is enabled.",
9696
);
97-
$this->log_level = new IntegerField(
98-
default: 3,
97+
$this->log_level = new StringField(
98+
default: "LOG_WARNING",
9999
choices: [
100-
0 => '0 - Emergency',
101-
1 => '1 - Alert',
102-
2 => '2 - Critical',
103-
3 => '3 - Error',
104-
4 => '4 - Warning',
105-
5 => '5 - Notice',
106-
6 => '6 - Info',
107-
7 => '7 - Debug',
100+
'LOG_DEBUG' => 'Debug',
101+
'LOG_INFO' => 'Info',
102+
'LOG_NOTICE' => 'Notice',
103+
'LOG_WARNING' => 'Warning',
104+
'LOG_ERR' => 'Error',
105+
'LOG_CRIT' => 'Critical',
106+
'LOG_ALERT' => 'Alert',
107+
'LOG_EMERG' => 'Emergency',
108108
],
109109
verbose_name: 'log level',
110-
help_text: 'Sets the log level for API logging. The log level determines the severity of messages that are
111-
logged. Setting a higher log level will include all messages of that level and lower severity.',
110+
help_text: 'Sets the log level for API logging. The log level determines the minimum severity of messages
111+
that should be logged.',
112112
);
113113
$this->allow_pre_releases = new BooleanField(
114114
default: false,

pfSense-pkg-RESTAPI/files/usr/local/share/pfSense-pkg-RESTAPI/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<keep_backup>enabled</keep_backup>
2121
<login_protection>enabled</login_protection>
2222
<log_successful_auth>disabled</log_successful_auth>
23-
<log_level>3</log_level>
23+
<log_level>LOG_WARNING</log_level>
2424
<hateoas>disabled</hateoas>
2525
<expose_sensitive_fields>disabled</expose_sensitive_fields>
2626
<override_sensitive_fields></override_sensitive_fields>

0 commit comments

Comments
 (0)