From c036c27ec72ae7a36667772cd64a9f367410b4b4 Mon Sep 17 00:00:00 2001
From: Andrew Dolgov <noreply@fakecake.org>
Date: Sun, 7 Mar 2021 09:05:23 +0300
Subject: [PATCH] logger: use constants instead of hardcoded string literals

---
 classes/config.php      |  2 +-
 classes/logger.php      | 10 +++++++---
 classes/pref/system.php |  2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/classes/config.php b/classes/config.php
index 3e643b2d0..567a019c6 100644
--- a/classes/config.php
+++ b/classes/config.php
@@ -84,7 +84,7 @@ class Config {
 																					Config::T_STRING ],
 		Config::CHECK_FOR_UPDATES => [ "true",							Config::T_BOOL ],
 		Config::PLUGINS => [ "auth_internal",							Config::T_STRING ],
-		Config::LOG_DESTINATION => [ "sql",								Config::T_STRING ],
+		Config::LOG_DESTINATION => [ Logger::LOG_DEST_SQL,			Config::T_STRING ],
 		Config::LOCAL_OVERRIDE_STYLESHEET => [ "local-overrides.css",
 																					Config::T_STRING ],
 		Config::DAEMON_MAX_CHILD_RUNTIME => [ 1800,					Config::T_INT ],
diff --git a/classes/logger.php b/classes/logger.php
index 864b66743..f8abb5f84 100755
--- a/classes/logger.php
+++ b/classes/logger.php
@@ -3,6 +3,10 @@ class Logger {
 	private static $instance;
 	private $adapter;
 
+	const LOG_DEST_SQL = "sql";
+	const LOG_DEST_STDOUT = "stdout";
+	const LOG_DEST_SYSLOG = "syslog";
+
 	const ERROR_NAMES = [
 		1			=> 'E_ERROR',
 		2			=> 'E_WARNING',
@@ -51,13 +55,13 @@ class Logger {
 
 	function __construct() {
 		switch (Config::get(Config::LOG_DESTINATION)) {
-		case "sql":
+		case self::LOG_DEST_SQL:
 			$this->adapter = new Logger_SQL();
 			break;
-		case "syslog":
+		case self::LOG_DEST_SYSLOG:
 			$this->adapter = new Logger_Syslog();
 			break;
-		case "stdout":
+		case self::LOG_DEST_STDOUT:
 			$this->adapter = new Logger_Stdout();
 			break;
 		default:
diff --git a/classes/pref/system.php b/classes/pref/system.php
index fb2379088..c79b5095d 100644
--- a/classes/pref/system.php
+++ b/classes/pref/system.php
@@ -165,7 +165,7 @@ class Pref_System extends Handler_Administrative {
 		$page = (int) ($_REQUEST["page"] ?? 0);
 		?>
 		<div dojoType='dijit.layout.AccordionContainer' region='center'>
-			<?php if (Config::get(Config::LOG_DESTINATION) == "sql") { ?>
+			<?php if (Config::get(Config::LOG_DESTINATION) == Logger::LOG_DEST_SQL) { ?>
 				<div dojoType='dijit.layout.AccordionPane' style='padding : 0' title='<i class="material-icons">report</i> <?= __('Event log') ?>'>
 					<?php
 						$this->_log_viewer($page, $severity);
-- 
GitLab