|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use Lizmap\Logger\Logger; |
3 | 4 | use Lizmap\Server\Server; |
| 5 | +use Psr\Log\LogLevel; |
4 | 6 |
|
5 | 7 | /** |
6 | 8 | * Manage and give access to lizmap configuration. |
@@ -52,6 +54,7 @@ class lizmapServices |
52 | 54 | 'requestProxyType', |
53 | 55 | 'requestProxyNotForDomain', |
54 | 56 | 'debugMode', |
| 57 | + 'logLevel', |
55 | 58 | 'cacheRootDirectory', |
56 | 59 | 'cacheRedisHost', |
57 | 60 | 'cacheRedisPort', |
@@ -315,6 +318,13 @@ class lizmapServices |
315 | 318 | */ |
316 | 319 | public $debugMode = ''; |
317 | 320 |
|
| 321 | + /** |
| 322 | + * @var string Log level |
| 323 | + * |
| 324 | + * @see LogLevel |
| 325 | + */ |
| 326 | + public $logLevel = Logger::DefaultLevel; |
| 327 | + |
318 | 328 | /** |
319 | 329 | * Cache root directory. |
320 | 330 | * |
@@ -452,6 +462,9 @@ public function __construct($readConfigPath, $globalConfig, $ldapEnabled, $varPa |
452 | 462 | } |
453 | 463 | } |
454 | 464 |
|
| 465 | + // Check log level property |
| 466 | + $this->checkLogLevel(); |
| 467 | + |
455 | 468 | if (!is_array($this->wmsServerHeaders)) { |
456 | 469 | $this->wmsServerHeaders = array(); |
457 | 470 | } |
@@ -613,9 +626,42 @@ public function modify($data) |
613 | 626 | } |
614 | 627 | } |
615 | 628 |
|
| 629 | + $this->checkLogLevel(); |
| 630 | + |
616 | 631 | return $modified; |
617 | 632 | } |
618 | 633 |
|
| 634 | + /** |
| 635 | + * Checking the log level property and update it if necessary. |
| 636 | + */ |
| 637 | + protected function checkLogLevel(): string |
| 638 | + { |
| 639 | + // check log level |
| 640 | + if (is_numeric($this->logLevel)) { |
| 641 | + $logLevel = (int) $this->logLevel; |
| 642 | + if ($logLevel < 0) { |
| 643 | + $this->logLevel = Logger::LogLevels[0]; |
| 644 | + } elseif ($logLevel > 7) { |
| 645 | + $this->logLevel = Logger::LogLevels[7]; |
| 646 | + } else { |
| 647 | + $this->logLevel = Logger::LogLevels[$logLevel]; |
| 648 | + } |
| 649 | + } elseif (!in_array($this->logLevel, Logger::LogLevels)) { |
| 650 | + $this->logLevel = Logger::DefaultLevel; |
| 651 | + } |
| 652 | + |
| 653 | + // Force log level to debug if debug mode is on |
| 654 | + if ($this->debugMode === '1' && $this->logLevel !== Logger::LogLevels[0]) { |
| 655 | + $this->logLevel = Logger::LogLevels[0]; |
| 656 | + } |
| 657 | + // Force debugMode to 1 if log level is debug |
| 658 | + if ($this->debugMode !== '1' && $this->logLevel === Logger::LogLevels[0]) { |
| 659 | + $this->debugMode = '1'; |
| 660 | + } |
| 661 | + |
| 662 | + return $this->logLevel; |
| 663 | + } |
| 664 | + |
619 | 665 | /** |
620 | 666 | * Host URL to the Lizmap QGIS Server API, taking care of the QGIS Server context : FCGI, QJazz, etc. |
621 | 667 | * |
|
0 commit comments