Skip to content

Commit

Permalink
Logging : Separate XMDS and Player logging settings. Introduce date b…
Browse files Browse the repository at this point in the history
…ased log level elevation setting. (#2458)
  • Loading branch information
PeterMis authored Apr 3, 2024
1 parent 4383f0d commit 2426c0c
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 72 deletions.
11 changes: 10 additions & 1 deletion lib/Controller/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -1378,10 +1378,19 @@ function editForm(Request $request, Response $response, $id)
: null;
$display->setUnmatchedProperty('auditingUntilIso', $auditingUntilIso);

// display profile dates
$displayProfile = $display->getDisplayProfile();

// Get the settings from the profile
$profile = $display->getSettings();
$displayTypes = $this->displayTypeFactory->query();

$elevateLogsUntil = $displayProfile->getSetting('elevateLogsUntil');
$elevateLogsUntilIso = !empty($elevateLogsUntil)
? Carbon::createFromTimestamp($elevateLogsUntil)->format(DateFormatHelper::getSystemFormat())
: null;
$displayProfile->setUnmatchedProperty('elevateLogsUntilIso', $elevateLogsUntilIso);

// Get a list of timezones
$timeZones = [];
foreach (DateFormatHelper::timezoneList() as $key => $value) {
Expand Down Expand Up @@ -1451,7 +1460,7 @@ function editForm(Request $request, Response $response, $id)
$this->getState()->template = 'display-form-edit';
$this->getState()->setData([
'display' => $display,
'displayProfile' => $display->getDisplayProfile(),
'displayProfile' => $displayProfile,
'lockOptions' => json_decode($display->getDisplayProfile()->getSetting('lockOptions', '[]'), true),
'layouts' => $layouts,
'profiles' => $this->displayProfileFactory->query(null, array('type' => $display->clientType)),
Expand Down
11 changes: 10 additions & 1 deletion lib/Controller/DisplayProfile.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand All @@ -21,13 +21,15 @@
*/
namespace Xibo\Controller;

use Carbon\Carbon;
use Slim\Http\Response as Response;
use Slim\Http\ServerRequest as Request;
use Stash\Interfaces\PoolInterface;
use Xibo\Factory\CommandFactory;
use Xibo\Factory\DayPartFactory;
use Xibo\Factory\DisplayProfileFactory;
use Xibo\Factory\PlayerVersionFactory;
use Xibo\Helper\DateFormatHelper;
use Xibo\Support\Exception\AccessDeniedException;
use Xibo\Support\Exception\NotFoundException;

Expand Down Expand Up @@ -369,6 +371,13 @@ public function editForm(Request $request, Response $response, $id)
}
}

// elevated logs
$elevateLogsUntil = $displayProfile->getSetting('elevateLogsUntil');
$elevateLogsUntilIso = !empty($elevateLogsUntil)
? Carbon::createFromTimestamp($elevateLogsUntil)->format(DateFormatHelper::getSystemFormat())
: null;
$displayProfile->setUnmatchedProperty('elevateLogsUntilIso', $elevateLogsUntilIso);

$this->getState()->template = 'displayprofile-form-edit';
$this->getState()->setData([
'displayProfile' => $displayProfile,
Expand Down
68 changes: 68 additions & 0 deletions lib/Controller/DisplayProfileConfigFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ public function editConfigFields($displayProfile, $sanitizedParams, $config = nu
$displayProfile->setSetting('logLevel', $sanitizedParams->getString('logLevel'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('elevateLogsUntil')) {
$this->handleChangedSettings(
'elevateLogsUntil',
($ownConfig)
? $displayProfile->getSetting('elevateLogsUntil')
: $display->getSetting('elevateLogsUntil'),
$sanitizedParams->getDate('elevateLogsUntil'),
$changedSettings
);
$displayProfile->setSetting(
'elevateLogsUntil',
$sanitizedParams->getDate('elevateLogsUntil')?->format('U'),
$ownConfig,
$config
);
}

if ($sanitizedParams->hasParam('versionMediaId')) {
$this->handleChangedSettings('versionMediaId', ($ownConfig) ? $displayProfile->getSetting('versionMediaId') : $display->getSetting('versionMediaId'), $sanitizedParams->getInt('versionMediaId'), $changedSettings);
$displayProfile->setSetting('versionMediaId', $sanitizedParams->getInt('versionMediaId'), $ownConfig, $config);
Expand Down Expand Up @@ -356,6 +373,23 @@ public function editConfigFields($displayProfile, $sanitizedParams, $config = nu
$displayProfile->setSetting('logLevel', $sanitizedParams->getString('logLevel'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('elevateLogsUntil')) {
$this->handleChangedSettings(
'elevateLogsUntil',
($ownConfig)
? $displayProfile->getSetting('elevateLogsUntil')
: $display->getSetting('elevateLogsUntil'),
$sanitizedParams->getDate('elevateLogsUntil'),
$changedSettings
);
$displayProfile->setSetting(
'elevateLogsUntil',
$sanitizedParams->getDate('elevateLogsUntil')?->format('U'),
$ownConfig,
$config
);
}

if ($sanitizedParams->hasParam('logToDiskLocation')){
$this->handleChangedSettings('logToDiskLocation', ($ownConfig) ? $displayProfile->getSetting('logToDiskLocation') : $display->getSetting('logToDiskLocation'), $sanitizedParams->getString('logToDiskLocation'), $changedSettings);
$displayProfile->setSetting('logToDiskLocation', $sanitizedParams->getString('logToDiskLocation'), $ownConfig, $config);
Expand Down Expand Up @@ -524,6 +558,23 @@ public function editConfigFields($displayProfile, $sanitizedParams, $config = nu
$displayProfile->setSetting('logLevel', $sanitizedParams->getString('logLevel'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('elevateLogsUntil')) {
$this->handleChangedSettings(
'elevateLogsUntil',
($ownConfig)
? $displayProfile->getSetting('elevateLogsUntil')
: $display->getSetting('elevateLogsUntil'),
$sanitizedParams->getDate('elevateLogsUntil'),
$changedSettings
);
$displayProfile->setSetting(
'elevateLogsUntil',
$sanitizedParams->getDate('elevateLogsUntil')?->format('U'),
$ownConfig,
$config
);
}

if ($sanitizedParams->hasParam('enableShellCommands')) {
$this->handleChangedSettings('enableShellCommands',($ownConfig) ? $displayProfile->getSetting('enableShellCommands') : $display->getSetting('enableShellCommands'), $sanitizedParams->getCheckbox('enableShellCommands'), $changedSettings);
$displayProfile->setSetting('enableShellCommands', $sanitizedParams->getCheckbox('enableShellCommands'), $ownConfig, $config);
Expand Down Expand Up @@ -649,6 +700,23 @@ public function editConfigFields($displayProfile, $sanitizedParams, $config = nu
$displayProfile->setSetting('logLevel', $sanitizedParams->getString('logLevel'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('elevateLogsUntil')) {
$this->handleChangedSettings(
'elevateLogsUntil',
($ownConfig)
? $displayProfile->getSetting('elevateLogsUntil')
: $display->getSetting('elevateLogsUntil'),
$sanitizedParams->getDate('elevateLogsUntil'),
$changedSettings
);
$displayProfile->setSetting(
'elevateLogsUntil',
$sanitizedParams->getDate('elevateLogsUntil')?->format('U'),
$ownConfig,
$config
);
}

if ($sanitizedParams->hasParam('versionMediaId')) {
$this->handleChangedSettings('versionMediaId', ($ownConfig) ? $displayProfile->getSetting('versionMediaId') : $display->getSetting('versionMediaId'), $sanitizedParams->getInt('versionMediaId'), $changedSettings);
$displayProfile->setSetting('versionMediaId', $sanitizedParams->getInt('versionMediaId'), $ownConfig, $config);
Expand Down
33 changes: 32 additions & 1 deletion lib/Entity/Display.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -676,6 +676,37 @@ public function isAuditing(): bool
return (!empty($this->auditingUntil) && $this->auditingUntil >= Carbon::now()->format('U'));
}

/**
* Does this display has elevated log level?
* @return bool
* @throws NotFoundException
*/
public function isElevatedLogging(): bool
{
$elevatedUntil = $this->getSetting('elevateLogsUntil', 0);

$this->getLog()->debug(sprintf(
'Testing whether this display has elevated log level. %d vs %d.',
$elevatedUntil,
Carbon::now()->format('U')
));

return (!empty($elevatedUntil) && $elevatedUntil >= Carbon::now()->format('U'));
}

/**
* Get current log level for this Display
* @return string
* @throws NotFoundException
*/
public function getLogLevel(): string
{
$restingLogLevel = $this->getSetting('logLevel', 'error');
$isElevated = $this->isElevatedLogging();

return $isElevated ? 'debug' : $restingLogLevel;
}

/**
* Set the Media Status to Incomplete
*/
Expand Down
5 changes: 5 additions & 0 deletions lib/Factory/DisplayProfileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function loadForType($type)
['name' => 'clientInfomationCtrlKey', 'default' => 0, 'type' => 'checkbox'],
['name' => 'clientInformationKeyCode', 'default' => 'I', 'type' => 'string'],
['name' => 'logLevel', 'default' => 'error', 'type' => 'string'],
['name' => 'elevateLogsUntil', 'default' => '', 'type' => 'int'],
['name' => 'logToDiskLocation', 'default' => '', 'type' => 'string'],
['name' => 'showInTaskbar', 'default' => 1, 'type' => 'checkbox'],
['name' => 'cursorStartPosition', 'default' => 'Unchanged', 'type' => 'string'],
Expand Down Expand Up @@ -236,6 +237,7 @@ public function loadForType($type)
['name' => 'storeHtmlOnInternal', 'default' => 0, 'type' => 'checkbox'],
['name' => 'useSurfaceVideoView', 'default' => 1, 'type' => 'checkbox'],
['name' => 'logLevel', 'default' => 'error'],
['name' => 'elevateLogsUntil', 'default' => '', 'type' => 'int'],
['name' => 'versionMediaId', 'default' => null],
['name' => 'startOnBoot', 'default' => 1, 'type' => 'checkbox'],
['name' => 'actionBarMode', 'default' => 1],
Expand Down Expand Up @@ -290,6 +292,7 @@ public function loadForType($type)
['name' => 'offsetX', 'default' => 0],
['name' => 'offsetY', 'default' => 0],
['name' => 'logLevel', 'default' => 'error'],
['name' => 'elevateLogsUntil', 'default' => '', 'type' => 'int'],
['name' => 'enableShellCommands', 'default' => 0, 'type' => 'checkbox'],
['name' => 'expireModifiedLayouts', 'default' => 0, 'type' => 'checkbox'],
['name' => 'maxConcurrentDownloads', 'default' => 2],
Expand Down Expand Up @@ -325,6 +328,7 @@ public function loadForType($type)
],
['name' => 'orientation', 'default' => 0],
['name' => 'logLevel', 'default' => 'error'],
['name' => 'elevateLogsUntil', 'default' => '', 'type' => 'int'],
['name' => 'versionMediaId', 'default' => null],
['name' => 'actionBarMode', 'default' => 1],
['name' => 'actionBarDisplayDuration', 'default' => 30],
Expand Down Expand Up @@ -360,6 +364,7 @@ public function loadForType($type)
],
['name' => 'orientation', 'default' => 0],
['name' => 'logLevel', 'default' => 'error'],
['name' => 'elevateLogsUntil', 'default' => '', 'type' => 'int'],
['name' => 'versionMediaId', 'default' => null],
['name' => 'actionBarMode', 'default' => 1],
['name' => 'actionBarDisplayDuration', 'default' => 30],
Expand Down
26 changes: 12 additions & 14 deletions lib/Xmds/LogProcessor.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/**
* Copyright (C) 2020 Xibo Signage Ltd
/*
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -61,16 +61,14 @@ public function setRoute($route)
}

/**
* @param $displayId
* @param bool $isAuditing
* @param int $displayId
* @param string $logLevel
*/
public function setDisplay($displayId, $isAuditing)
public function setDisplay($displayId, $logLevel)
{
if ($isAuditing) {
foreach($this->log->getHandlers() as $handler) {
if ($handler instanceof DatabaseLogHandler) {
$handler->setLevel(\Xibo\Service\LogService::resolveLogLevel('debug'));
}
foreach ($this->log->getHandlers() as $handler) {
if ($handler instanceof DatabaseLogHandler) {
$handler->setLevel(\Xibo\Service\LogService::resolveLogLevel($logLevel));
}
}

Expand All @@ -85,11 +83,11 @@ public function getLevel()
{
$level = Logger::ERROR;

foreach($this->log->getHandlers() as $handler) {
foreach ($this->log->getHandlers() as $handler) {
if ($handler instanceof DatabaseLogHandler) {
$level = $handler->getLevel();
} else {
$this->log->error('Log level not set in DabaseLogHandler');
$this->log->error('Log level not set in DatabaseLogHandler');
}
}

Expand Down Expand Up @@ -117,4 +115,4 @@ public function __invoke(array $record)

return $record;
}
}
}
Loading

0 comments on commit 2426c0c

Please sign in to comment.