Skip to content

Commit 2f49031

Browse files
committed
Config Logger
1 parent f268033 commit 2f49031

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

lizmap/modules/lizmap/classes/lizmap.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static function getAppContext()
9999
public static function getLogger()
100100
{
101101
if (!self::$logger) {
102-
self::$logger = new Logger();
102+
self::$logger = new Logger(self::getServices()->logLevel);
103103
}
104104

105105
return self::$logger;

lizmap/modules/lizmap/classes/lizmapServices.class.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3+
use Lizmap\Logger\Logger;
34
use Lizmap\Server\Server;
5+
use Psr\Log\LogLevel;
46

57
/**
68
* Manage and give access to lizmap configuration.
@@ -52,6 +54,7 @@ class lizmapServices
5254
'requestProxyType',
5355
'requestProxyNotForDomain',
5456
'debugMode',
57+
'logLevel',
5558
'cacheRootDirectory',
5659
'cacheRedisHost',
5760
'cacheRedisPort',
@@ -315,6 +318,13 @@ class lizmapServices
315318
*/
316319
public $debugMode = '';
317320

321+
/**
322+
* @var string Log level
323+
*
324+
* @see LogLevel
325+
*/
326+
public $logLevel = Logger::DefaultLevel;
327+
318328
/**
319329
* Cache root directory.
320330
*
@@ -452,6 +462,9 @@ public function __construct($readConfigPath, $globalConfig, $ldapEnabled, $varPa
452462
}
453463
}
454464

465+
// Check log level property
466+
$this->checkLogLevel();
467+
455468
if (!is_array($this->wmsServerHeaders)) {
456469
$this->wmsServerHeaders = array();
457470
}
@@ -618,9 +631,33 @@ public function modify($data)
618631
}
619632
}
620633

634+
$this->checkLogLevel();
635+
621636
return $modified;
622637
}
623638

639+
/**
640+
* Checking the log level property and update it if necessary.
641+
*/
642+
protected function checkLogLevel(): string
643+
{
644+
// check log level
645+
if (is_numeric($this->logLevel)) {
646+
$logLevel = (int) $this->logLevel;
647+
if ($logLevel < 0) {
648+
$this->logLevel = Logger::LogLevels[0];
649+
} elseif ($logLevel > 7) {
650+
$this->logLevel = Logger::LogLevels[7];
651+
} else {
652+
$this->logLevel = Logger::LogLevels[$logLevel];
653+
}
654+
} elseif (!in_array($this->logLevel, Logger::LogLevels)) {
655+
$this->logLevel = Logger::DefaultLevel;
656+
}
657+
658+
return $this->logLevel;
659+
}
660+
624661
/**
625662
* Host URL to the Lizmap QGIS Server API, taking care of the QGIS Server context : FCGI, QJazz, etc.
626663
*

tests/units/classes/lizmapServicesTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,23 @@ public static function getModifyLocalData()
235235
'adminContactEmail' => '[email protected]',
236236
'debugMode' => 'off',
237237
);
238+
$testModify4_1 = array(
239+
'appName' => 'Lizmap',
240+
'adminContactEmail' => '[email protected]',
241+
'logLevel' => 'debug',
242+
);
243+
$testModify5_1 = array(
244+
'appName' => 'Lizmap',
245+
'adminContactEmail' => '[email protected]',
246+
'logLevel' => '1',
247+
);
238248

239249
return array(
240250
array($testModify1, $testModify1_1, null, null, true),
241251
array($testModify1, $testModify2_1, 'adminContactEmail', '[email protected]', true),
242252
array($testModify1, $testModify3_1, 'debugMode', 'off', true),
253+
array($testModify1, $testModify4_1, 'logLevel', 'debug', true),
254+
array($testModify1, $testModify5_1, 'logLevel', 'alert', true),
243255
array($testModify1, null, null, null, false),
244256
array($testModify2, $testModify1_1, 'adminContactEmail', '[email protected]', true),
245257
array(null, $testModify1_1, 'adminContactEmail', '[email protected]', true),
@@ -325,6 +337,7 @@ public function testSaveIntoIni($dataModification, $expectedIniValues, $expected
325337
'requestProxyNotForDomain',
326338
'cacheRedisHost',
327339
'cacheRedisPort',
340+
'logLevel',
328341
);
329342

330343
$testLizmapServices = new LizmapServices(

0 commit comments

Comments
 (0)