Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging : Separate XMDS and Player logging settings. #2458

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/Controller/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -1377,10 +1377,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 @@ -1450,7 +1459,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 @@ -51,52 +51,52 @@

case 'android':
if ($sanitizedParams->hasParam('emailAddress')) {
$this->handleChangedSettings('emailAddress', ($ownConfig) ? $displayProfile->getSetting('emailAddress') : $display->getSetting('emailAddress'), $sanitizedParams->getString('emailAddress'), $changedSettings);

Check warning on line 54 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 227 characters
$displayProfile->setSetting('emailAddress', $sanitizedParams->getString('emailAddress'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('settingsPassword')) {
$this->handleChangedSettings('settingsPassword', ($ownConfig) ? $displayProfile->getSetting('settingsPassword') : $display->getSetting('settingsPassword'), $sanitizedParams->getString('settingsPassword'), $changedSettings);

Check warning on line 59 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 243 characters
$displayProfile->setSetting('settingsPassword', $sanitizedParams->getString('settingsPassword'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('collectInterval')) {
$this->handleChangedSettings('collectInterval', ($ownConfig) ? $displayProfile->getSetting('collectInterval') : $display->getSetting('collectInterval'), $sanitizedParams->getInt('collectInterval'), $changedSettings);

Check warning on line 64 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 236 characters
$displayProfile->setSetting('collectInterval', $sanitizedParams->getInt('collectInterval'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('downloadStartWindow')) {
$this->handleChangedSettings('downloadStartWindow', ($ownConfig) ? $displayProfile->getSetting('downloadStartWindow') : $display->getSetting('downloadStartWindow'), $sanitizedParams->getString('downloadStartWindow'), $changedSettings);

Check warning on line 69 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 255 characters
$displayProfile->setSetting('downloadStartWindow', $sanitizedParams->getString('downloadStartWindow'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('downloadEndWindow')) {
$this->handleChangedSettings('downloadEndWindow', ($ownConfig) ? $displayProfile->getSetting('downloadEndWindow') : $display->getSetting('downloadEndWindow'), $sanitizedParams->getString('downloadEndWindow'), $changedSettings);

Check warning on line 74 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 247 characters
$displayProfile->setSetting('downloadEndWindow', $sanitizedParams->getString('downloadEndWindow'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('xmrNetworkAddress')) {
$this->handleChangedSettings('xmrNetworkAddress', ($ownConfig) ? $displayProfile->getSetting('xmrNetworkAddress') : $display->getSetting('xmrNetworkAddress'), $sanitizedParams->getString('xmrNetworkAddress'), $changedSettings);

Check warning on line 79 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 247 characters
$displayProfile->setSetting('xmrNetworkAddress', $sanitizedParams->getString('xmrNetworkAddress'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('statsEnabled')) {
$this->handleChangedSettings('statsEnabled', ($ownConfig) ? $displayProfile->getSetting('statsEnabled') : $display->getSetting('statsEnabled'), $sanitizedParams->getCheckbox('statsEnabled'), $changedSettings);

Check warning on line 84 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 229 characters
$displayProfile->setSetting('statsEnabled', $sanitizedParams->getCheckbox('statsEnabled'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('aggregationLevel')) {
$this->handleChangedSettings('aggregationLevel', ($ownConfig) ? $displayProfile->getSetting('aggregationLevel') : $display->getSetting('aggregationLevel'), $sanitizedParams->getString('aggregationLevel'), $changedSettings);

Check warning on line 89 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 243 characters
$displayProfile->setSetting('aggregationLevel', $sanitizedParams->getString('aggregationLevel'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('orientation')) {
$this->handleChangedSettings('orientation', ($ownConfig) ? $displayProfile->getSetting('orientation') : $display->getSetting('orientation'), $sanitizedParams->getInt('orientation'), $changedSettings);

Check warning on line 94 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 220 characters
$displayProfile->setSetting('orientation', $sanitizedParams->getInt('orientation'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('screenDimensions')) {
$this->handleChangedSettings('screenDimensions', ($ownConfig) ? $displayProfile->getSetting('screenDimensions') : $display->getSetting('screenDimensions'), $sanitizedParams->getString('screenDimensions'), $changedSettings);

Check warning on line 99 in lib/Controller/DisplayProfileConfigFields.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 243 characters
$displayProfile->setSetting('screenDimensions', $sanitizedParams->getString('screenDimensions'), $ownConfig, $config);
}

Expand All @@ -120,6 +120,23 @@
$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 @@
$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 @@
$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 @@
$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
Loading