Skip to content
Open
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
7 changes: 7 additions & 0 deletions docker/update-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* @param IniModifier $iniFileModifier
* @param mixed $varname
*/
function load_include_config($varname, $iniFileModifier)
{
Expand Down Expand Up @@ -172,6 +173,12 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries = 10,
// DropIn capabilities: Merge all ini file in LIZMAP_LIZMAPCONFIG_INCLUDE
load_include_config('LIZMAP_LIZMAPCONFIG_INCLUDE', $lizmapConfig);

// Enable metrics
$log_level = getenv('LIZMAP_LOGLEVEL');
if (is_numeric($log_level) || $log_level !== '') {
$lizmapConfig->setValue('logLevel', $log_level, 'services');
}

// Enable metrics
$logger_metric = getenv('LIZMAP_LOGMETRICS');
if ($logger_metric !== false) {
Expand Down
10 changes: 10 additions & 0 deletions lizmap/app/system/mainconfig.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,14 @@
[logger]
_all=
default=file
emergency=file
alert=file
critical=file
error=file
warning=file
notice=file
info=file
debug=file
;deprecated=syslog
strict=file
;sql=syslog
Expand All @@ -203,9 +208,14 @@

[fileLogger]
default=messages.log
emergency=errors.log
alert=errors.log
critical=errors.log
error=errors.log
warning=errors.log
notice=errors.log
info=errors.log
debug=errors.log
strict=errors.log
;metric=time.log
auth=messages.log
Expand Down
3 changes: 2 additions & 1 deletion lizmap/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"violet/streaming-json-encoder": "^1.1.5",
"guzzlehttp/guzzle": "^7.7.0",
"halaxa/json-machine": "^1.1",
"kevinrob/guzzle-cache-middleware": "^6.0"
"kevinrob/guzzle-cache-middleware": "^6.0",
"psr/log": "2.*"
},
"minimum-stability": "stable",
"config": {
Expand Down
13 changes: 13 additions & 0 deletions lizmap/modules/admin/forms/config_services.form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@
<item value="1" locale="admin~admin.form.admin_services.debugMode.1.label"/>
</menulist>

<menulist ref="logLevel" required="true">
<label locale="admin~admin.form.admin_services.logLevel.label"/>
<help locale="admin~admin.form.admin_services.logLevel.help"/>
<item value="emergency" locale="admin~admin.form.admin_services.logLevel.emergency.label"/>
<item value="alert" locale="admin~admin.form.admin_services.logLevel.alert.label"/>
<item value="critical" locale="admin~admin.form.admin_services.logLevel.critical.label"/>
<item value="error" selected="true" locale="admin~admin.form.admin_services.logLevel.error.label"/>
<item value="warning" locale="admin~admin.form.admin_services.logLevel.warning.label"/>
<item value="notice" locale="admin~admin.form.admin_services.logLevel.notice.label"/>
<item value="info" locale="admin~admin.form.admin_services.logLevel.info.label"/>
<item value="debug" locale="admin~admin.form.admin_services.logLevel.debug.label"/>
</menulist>

<group ref="requestProxyEnabled" withcheckbox="true">
<oncheckvalue locale="admin~admin.form.admin_services.requestProxy.enabled" value="1"/>
<onuncheckvalue locale="admin~admin.form.admin_services.requestProxy.disabled" value="0" />
Expand Down
10 changes: 10 additions & 0 deletions lizmap/modules/admin/locales/en_US/admin.UTF-8.properties
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ form.admin_services.requestProxyNotForDomain.label=Domains for which the proxy w
form.admin_services.debugMode.label=Debug mode
form.admin_services.debugMode.0.label=Off
form.admin_services.debugMode.1.label=Log
form.admin_services.logLevel.label=Log level
form.admin_services.logLevel.help=Select the level of severity of the messages to log.
form.admin_services.logLevel.emergency.label=Emergency: indicates that the system is unusable and requires immediate attention.
form.admin_services.logLevel.alert.label=Alert: indicates that immediate action is necessary to resolve a critical issue.
form.admin_services.logLevel.critical.label=Critical: signifies critical conditions in the program that demand intervention to prevent system failure.
form.admin_services.logLevel.error.label=Error: indicates error conditions that impair some operation but are less severe than critical situations.
form.admin_services.logLevel.warning.label=Warning: signifies potential issues that may lead to errors or unexpected behavior in the future if not addressed.
form.admin_services.logLevel.notice.label=Notice: applies to normal but significant conditions that may require monitoring.
form.admin_services.logLevel.info.label=Info: includes messages that provide a record of the normal operation of the system.
form.admin_services.logLevel.debug.label=Debug: intended for logging detailed information about the system for debugging purposes.
form.admin_services.onlyMaps.label=Disable landing page
form.admin_services.onlyMaps.help=If set to "On", no landing page will be available.
form.admin_services.projectSwitcher.label=Show projects switcher
Expand Down
20 changes: 19 additions & 1 deletion lizmap/modules/lizmap/classes/lizmap.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Lizmap\Logger as Log;
use Lizmap\Logger\Config as LogConfig;
use Lizmap\Logger\Item as LogItem;
use Lizmap\Logger\Logger;
use Lizmap\Project\Project;

/**
Expand Down Expand Up @@ -54,6 +55,11 @@ class lizmap
*/
protected static $appContext;

/**
* @var null|Logger The logger instance
*/
protected static $logger;

/**
* this is a static class, so private constructor.
*/
Expand Down Expand Up @@ -87,6 +93,18 @@ public static function getAppContext()
return self::$appContext;
}

/**
* @return Logger The logger instance
*/
public static function getLogger()
{
if (!self::$logger) {
self::$logger = new Logger(self::getServices()->logLevel);
}

return self::$logger;
}

public static function saveServices()
{
$ini = new IniModifier(jApp::varConfigPath('lizmapConfig.ini.php'));
Expand Down Expand Up @@ -495,6 +513,6 @@ public static function logMetric($label, $service, $payload = array())

$logMessage = new Log\MetricsLogMessage($log, 'metric');

jLog::log($logMessage);
self::getLogger()->info($logMessage);
}
}
46 changes: 46 additions & 0 deletions lizmap/modules/lizmap/classes/lizmapServices.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use Lizmap\Logger\Logger;
use Lizmap\Server\Server;
use Psr\Log\LogLevel;

/**
* Manage and give access to lizmap configuration.
Expand Down Expand Up @@ -52,6 +54,7 @@ class lizmapServices
'requestProxyType',
'requestProxyNotForDomain',
'debugMode',
'logLevel',
'cacheRootDirectory',
'cacheRedisHost',
'cacheRedisPort',
Expand Down Expand Up @@ -315,6 +318,13 @@ class lizmapServices
*/
public $debugMode = '';

/**
* @var string Log level
*
* @see LogLevel
*/
public $logLevel = Logger::DefaultLevel;

/**
* Cache root directory.
*
Expand Down Expand Up @@ -452,6 +462,9 @@ public function __construct($readConfigPath, $globalConfig, $ldapEnabled, $varPa
}
}

// Check log level property
$this->checkLogLevel();

if (!is_array($this->wmsServerHeaders)) {
$this->wmsServerHeaders = array();
}
Expand Down Expand Up @@ -613,9 +626,42 @@ public function modify($data)
}
}

$this->checkLogLevel();

return $modified;
}

/**
* Checking the log level property and update it if necessary.
*/
protected function checkLogLevel(): string
{
// check log level
if (is_numeric($this->logLevel)) {
$logLevel = (int) $this->logLevel;
if ($logLevel < 0) {
$this->logLevel = Logger::LogLevels[0];
} elseif ($logLevel > 7) {
$this->logLevel = Logger::LogLevels[7];
} else {
$this->logLevel = Logger::LogLevels[$logLevel];
}
} elseif (!in_array($this->logLevel, Logger::LogLevels)) {
$this->logLevel = Logger::DefaultLevel;
}

// Force log level to debug if debug mode is on
if ($this->debugMode === '1' && $this->logLevel !== Logger::LogLevels[0]) {
$this->logLevel = Logger::LogLevels[0];
}
// Force debugMode to 1 if log level is debug
if ($this->debugMode !== '1' && $this->logLevel === Logger::LogLevels[0]) {
$this->debugMode = '1';
}

return $this->logLevel;
}

/**
* Host URL to the Lizmap QGIS Server API, taking care of the QGIS Server context : FCGI, QJazz, etc.
*
Expand Down
15 changes: 13 additions & 2 deletions lizmap/modules/lizmap/lib/App/JelixContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Lizmap\App;

use Jelix\IniFile\IniModifier;
use Lizmap\Logger\Logger;

class JelixContext implements AppContextInterface
{
Expand Down Expand Up @@ -210,7 +211,11 @@ public function flushCache($profile = '')
*/
public function logMessage($message, $cat = 'default')
{
\jLog::log($message, $cat);
if (in_array($cat, Logger::LogLevels)) {
\lizmap::getLogger()->log($cat, $message);
} else {
\jLog::log($message, $cat);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a long term, maybe this function should launch a deprecated error ?

We may add a CustomLogger acting as PSR-3 logger but for the lizadmin file ?

// \lizmap::getAppContext()->logMessage($errormsg, 'lizmapadmin');
lizmap::getCustomLoger()->debug($errormsg);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're rights @nworr but do we still need a lizmap-admin log ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so , the aim of "lizmap-admin" is to display on admin backend some events (and keep more sensitive events to the errors.log, unreadable for non "sysadmin" users ) .

}

/**
Expand All @@ -221,7 +226,13 @@ public function logMessage($message, $cat = 'default')
*/
public function logException($exception, $cat = 'default')
{
\jLog::logEx($exception, $cat);
if (in_array($cat, Logger::LogLevels)) {
if (\lizmap::getLogger()->isLevelHighEnough($cat)) {
\jLog::logEx($exception, $cat);
}
} else {
\jLog::logEx($exception, $cat);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public function getData($form)
if ($wkt && \lizmapWkt::check($wkt)) {
$geom = \lizmapWkt::parse($wkt);
if ($geom === null) {
\jLog::log('Parsing WKT failed! '.$wkt, 'error');
\lizmap::getLogger()->error(
'Parsing WKT failed! {wkt}',
array('wkt' => $wkt)
);
}
}
} else {
Expand Down
Loading
Loading