Skip to content

Commit

Permalink
Merge pull request #15 from haruanm/added_stacktrace
Browse files Browse the repository at this point in the history
Added stacktrace
  • Loading branch information
haruanm authored Jan 26, 2021
2 parents 42327ee + 176e689 commit 8a25323
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions runtime/lib/connection/PropelPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,24 @@ public function log($msg, $level = null, $methodName = null, array $debugSnapsho
}
}

/**
* Returns a string with files, lines e functions of the stacktrace to this method
*
* @return str
*/
function generateCallTrace()
{
$stacktrace = debug_backtrace(2);
$stackLog = '';
foreach ($stacktrace as $stack) {
$file = isset($stack['file']) ? $stack['file'] : "Unknown file";
$line = isset($stack['line']) ? $stack['line'] : "Unknown line";
$stackLog .= $file.':'.$line.' '.$stack['function']."()\n";
}

return $stackLog;
}

/**
* Returns a snapshot of the current values of some functions useful in debugging.
*
Expand All @@ -661,6 +679,7 @@ public function getDebugSnapshot()
'microtime' => microtime(true),
'memory_get_usage' => memory_get_usage($this->getLoggingConfig('realmemoryusage', false)),
'memory_get_peak_usage' => memory_get_peak_usage($this->getLoggingConfig('realmemoryusage', false)),
'stacktrace' => $this->generateCallTrace(),
);
} else {
throw new PropelException('Should not get debug snapshot when not debugging');
Expand Down Expand Up @@ -754,6 +773,10 @@ protected function getLogPrefix($methodName, $debugSnapshot)
$value = $this->connectionName;
break;

case 'stacktrace':
$value = $debugSnapshot['stacktrace'];
break;

default:
$value = 'n/a';
break;
Expand Down

0 comments on commit 8a25323

Please sign in to comment.