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

add system setting for error.log which defaults to 'logs/' and uses this configurable path for logging #12352

Closed
wants to merge 10 commits into from
9 changes: 9 additions & 0 deletions _build/data/transport.core.system_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2032,4 +2032,13 @@
'area' => 'site',
'editedon' => null,
), '', true, true);
$settings['error_log_path']= $xpdo->newObject('modSystemSetting');
$settings['error_log_path']->fromArray(array (
'key' => 'error_log_path',
'value' => 'logs/',
'xtype' => 'textfield',
'namespace' => 'core',
'area' => 'site',
'editedon' => null,
), '', true, true);
return $settings;
3 changes: 2 additions & 1 deletion core/model/modx/processors/system/errorlog/clear.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public function checkPermissions() {
return $this->modx->hasPermission('error_log_erase');
}
public function process() {
$file = $this->modx->getOption(xPDO::OPT_CACHE_PATH).'logs/error.log';
$error_log_path = $this->modx->getOption('error_log_path');
$file = MODX_BASE_PATH.$error_log_path.'error.log';
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an absolute path, eg /home/website.tld/core/error.log

$content = '';
$tooLarge = false;
if (file_exists($file)) {
Expand Down
9 changes: 5 additions & 4 deletions core/model/modx/processors/system/errorlog/download.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ public function checkPermissions() {
return $this->modx->hasPermission('error_log_view');
}
public function process() {
$f = $this->modx->getOption(xPDO::OPT_CACHE_PATH).'logs/error.log';
if (!file_exists($f)) {
$error_log_path = $this->modx->getOption('error_log_path');
$file = MODX_BASE_PATH.$error_log_path.'error.log';
if (!file_exists($file)) {
return $this->failure();
}
header('Content-Type: application/force-download');
header('Content-Length: ' . filesize($f));
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="error.'.time().'.log');
ob_get_level() && @ob_end_flush();
readfile($f);
readfile($file);
die();
}
}
Expand Down
11 changes: 6 additions & 5 deletions core/model/modx/processors/system/errorlog/get.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ public function checkPermissions() {
return $this->modx->hasPermission('error_log_view');
}
public function process() {
$f = $this->modx->getOption(xPDO::OPT_CACHE_PATH).'logs/error.log';
$error_log_path = $this->modx->getOption('error_log_path');
$file = MODX_BASE_PATH.$error_log_path.'error.log';
$content = '';
$tooLarge = false;
if (file_exists($f)) {
$size = round(@filesize($f) / 1000 / 1000,2);
if (file_exists($file)) {
$size = round(@filesize($file) / 1000 / 1000,2);
if ($size > 1) {
$tooLarge = true;
} else {
$content = @file_get_contents($f);
$content = @file_get_contents($file);
}
}
$la = array(
'name' => $f,
'name' => $file,
'log' => $content,
'tooLarge' => $tooLarge,
);
Expand Down
4 changes: 3 additions & 1 deletion core/xpdo/xpdo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,9 @@ protected function _log($level, $msg, $target= '', $def= '', $file= '', $line= '
@ob_end_clean();
if ($target=='FILE' && $this->getCacheManager()) {
$filename = isset($targetOptions['filename']) ? $targetOptions['filename'] : 'error.log';
$filepath = isset($targetOptions['filepath']) ? $targetOptions['filepath'] : $this->getCachePath() . xPDOCacheManager::LOG_DIR;
$errorlog_setting = $this->getObject('modSystemSetting', 'error_log_path');
$errorlog_path = $errorlog_setting->get('value');
$filepath = isset($targetOptions['filepath']) ? $targetOptions['filepath'] : $errorlog_path;
$this->cacheManager->writeFile($filepath . $filename, $content, 'a');
} elseif ($target=='ARRAY' && isset($targetOptions['var']) && is_array($targetOptions['var'])) {
$targetOptions['var'][] = $content;
Expand Down
3 changes: 2 additions & 1 deletion manager/controllers/default/system/event.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function loadCustomCssJs() {
* @return mixed
*/
public function process(array $scriptProperties = array()) {
$f = $this->modx->getOption(xPDO::OPT_CACHE_PATH).'logs/error.log';
$error_log_path = $this->modx->getOption('error_log_path');
$f = MODX_BASE_PATH.$error_log_path.'error.log';
$this->logArray['name'] = $f;
if (file_exists($f)) {
$this->logArray['size'] = round(@filesize($f) / 1000 / 1000,2);
Expand Down