logger: use constants instead of hardcoded string literals

This commit is contained in:
Andrew Dolgov 2021-03-07 09:05:23 +03:00
parent 17650775d2
commit c036c27ec7
3 changed files with 9 additions and 5 deletions

View File

@ -84,7 +84,7 @@ class Config {
Config::T_STRING ], Config::T_STRING ],
Config::CHECK_FOR_UPDATES => [ "true", Config::T_BOOL ], Config::CHECK_FOR_UPDATES => [ "true", Config::T_BOOL ],
Config::PLUGINS => [ "auth_internal", Config::T_STRING ], 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::LOCAL_OVERRIDE_STYLESHEET => [ "local-overrides.css",
Config::T_STRING ], Config::T_STRING ],
Config::DAEMON_MAX_CHILD_RUNTIME => [ 1800, Config::T_INT ], Config::DAEMON_MAX_CHILD_RUNTIME => [ 1800, Config::T_INT ],

View File

@ -3,6 +3,10 @@ class Logger {
private static $instance; private static $instance;
private $adapter; private $adapter;
const LOG_DEST_SQL = "sql";
const LOG_DEST_STDOUT = "stdout";
const LOG_DEST_SYSLOG = "syslog";
const ERROR_NAMES = [ const ERROR_NAMES = [
1 => 'E_ERROR', 1 => 'E_ERROR',
2 => 'E_WARNING', 2 => 'E_WARNING',
@ -51,13 +55,13 @@ class Logger {
function __construct() { function __construct() {
switch (Config::get(Config::LOG_DESTINATION)) { switch (Config::get(Config::LOG_DESTINATION)) {
case "sql": case self::LOG_DEST_SQL:
$this->adapter = new Logger_SQL(); $this->adapter = new Logger_SQL();
break; break;
case "syslog": case self::LOG_DEST_SYSLOG:
$this->adapter = new Logger_Syslog(); $this->adapter = new Logger_Syslog();
break; break;
case "stdout": case self::LOG_DEST_STDOUT:
$this->adapter = new Logger_Stdout(); $this->adapter = new Logger_Stdout();
break; break;
default: default:

View File

@ -165,7 +165,7 @@ class Pref_System extends Handler_Administrative {
$page = (int) ($_REQUEST["page"] ?? 0); $page = (int) ($_REQUEST["page"] ?? 0);
?> ?>
<div dojoType='dijit.layout.AccordionContainer' region='center'> <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') ?>'> <div dojoType='dijit.layout.AccordionPane' style='padding : 0' title='<i class="material-icons">report</i> <?= __('Event log') ?>'>
<?php <?php
$this->_log_viewer($page, $severity); $this->_log_viewer($page, $severity);