Skip to content

Commit

Permalink
v0.6.7 fix for exceptionlog command
Browse files Browse the repository at this point in the history
  • Loading branch information
smxsm committed Oct 18, 2018
1 parent e012340 commit 2aab2c4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# OXRUN CHANGELOG

## v0.6.7

* fix for exceptionlog command with new log file name and structure
since OXID 6.0.3

## v0.6.6

* fix for loading from modules dir if namespace does not match folder name(s)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "smxsm/oxrun",
"description": "Oxrun provides a cli toolset for the OXID eShop",
"license": "MIT",
"version": "v0.6.6",
"version": "v0.6.7",
"support": {
"issues": "https://github.com/smxsm/oxrun/issues"
},
Expand Down
Binary file modified oxrun.phar
Binary file not shown.
43 changes: 32 additions & 11 deletions src/Oxrun/Command/Log/ExceptionLogCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class ExceptionLogCommand extends Command
protected $numLines = 100;

/**
* Regex patterns for log entries
* Regex patterns for EXCEPTION_LOG.txt log entries
*
* @var array
*/
protected $aRegEx = [
protected $aRegExLegacy = [
'DATE' => '/\[([0-9]{2}\s[A-Za-z]{3}\s[0-9:.]*\s[0-9]{4})\]/',
// \x5c stands for "backslash",
// see https://stackoverflow.com/questions/11044136/right-way-to-escape-backslash-in-php-regex
Expand All @@ -52,6 +52,18 @@ class ExceptionLogCommand extends Command
'FILE' => '/\[file\s([%^A-Za-z0-9\/\.\-\_]*)]/',
'TRACE' => '/(#[0-9]*\s.*|\[line\s[0-9]{1,}.*\])/sim',
];
/**
* Regex patterns for oxideshop.log log entries
*
* @var array
*/
protected $aRegEx = [
'DATE' => '/\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\]/', // [2018-10-17 15:19:38]
'ERROR_TYPE' => '/.*\sLogger\.([A-Z]*):\s/', // e.g. OXID Logger.ERROR:
'ERROR_CODE' => '/\(code:\s([0-9]*)/', // e.g. (Error(code: 0):
'FILE' => '/\sat\s([%^A-Za-z0-9\/\.\-\_]*):/',
'TRACE' => '/(#[0-9]*\s.*|\[line\s[0-9]{1,}.*\])/sim',
];

/**
* Configures the current command.
Expand Down Expand Up @@ -86,8 +98,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$oConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
$this->sLogFile = $oConfig->getConfigParam('sShopDir') . DIRECTORY_SEPARATOR . "log" . DIRECTORY_SEPARATOR. "EXCEPTION_LOG.txt";

$isLegacyFile = false;
$this->sLogFile = $oConfig->getConfigParam('sShopDir') . DIRECTORY_SEPARATOR . "log" . DIRECTORY_SEPARATOR. "oxideshop.log";
if (!file_exists($this->sLogFile)) {
$isLegacyFile = true;
// fallback OXID < 6.0.3
$this->sLogFile = $oConfig->getConfigParam('sShopDir') . DIRECTORY_SEPARATOR . "log" . DIRECTORY_SEPARATOR. "EXCEPTION_LOG.txt";
}
$output->writeln("<info>Logfile: {$this->sLogFile}</info>");

$aEntries = $this->getLogEntries($output);
Expand All @@ -104,25 +121,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
// parse info for table view
$aSplitEntries = array();
$aSplitEntries[] = array("Date", "Type", "Code", "File", "Message");
$mRegEx = $this->aRegEx;
if ($isLegacyFile) {
$mRegEx = $this->aRegExLegacy;
}
foreach ($aEntries as $logEntry) {
$aMatches = array();
preg_match($this->aRegEx['ERROR_TYPE'], $logEntry, $aMatches);
$sErrType = $aMatches[2];
preg_match($mRegEx['ERROR_TYPE'], $logEntry, $aMatches);
$sErrType = $aMatches[1];

$aMatches = array();
preg_match($this->aRegEx['DATE'], $logEntry, $aMatches);
preg_match($mRegEx['DATE'], $logEntry, $aMatches);
$sDate = $aMatches[1];

$aMatches = array();
preg_match($this->aRegEx['ERROR_CODE'], $logEntry, $aMatches);
preg_match($mRegEx['ERROR_CODE'], $logEntry, $aMatches);
$sErrCode = $aMatches[1];

$aMatches = array();
preg_match($this->aRegEx['FILE'], $logEntry, $aMatches);
preg_match($mRegEx['FILE'], $logEntry, $aMatches);
$sErrFile = $aMatches[1];

$aMatches = array();
preg_match($this->aRegEx['TRACE'], $logEntry, $aMatches);
preg_match($mRegEx['TRACE'], $logEntry, $aMatches);
$sErrTrace = $aMatches[1];

$aSplitEntries[] = array($sDate, $sErrType, $sErrCode, $sErrFile, $sErrTrace);
Expand Down Expand Up @@ -171,10 +192,10 @@ protected function getLogEntries($output)
$results[] = $line;
$count++;
}
return $results;
} else {
$output->writeln("<error>No logfile found!</error>");
}
return $results;
}

/**
Expand Down

0 comments on commit 2aab2c4

Please sign in to comment.