Skip to content

Commit

Permalink
Merge pull request #34 from JackieDo/version-2.x
Browse files Browse the repository at this point in the history
Update core
  • Loading branch information
JackieDo authored Apr 11, 2020
2 parents 0f8c3b6 + cbd175a commit 8782d83
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ php:
- 5.4
- 5.5
- 5.6
- 7.1
- 7.2
- 7.3

before_script:
- travis_retry composer self-update
Expand Down
2 changes: 1 addition & 1 deletion src/Jackiedo/LogReader/Entities/LogContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function assignAttributes()
$parsed = $this->parser->parseLogContext($this->content);

foreach ($parsed as $key => $value) {
$this->{$key} = $value;
$this->{$key} = str_replace('\\\\', '\\', $value);
}
}
}
4 changes: 1 addition & 3 deletions src/Jackiedo/LogReader/Entities/LogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ protected function setFilePath($path = null)
*/
protected function setContext($context = null)
{
if ($context) {
$this->context = new LogContext($this->parser, $context);
}
$this->context = new LogContext($this->parser, $context);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Jackiedo/LogReader/Entities/TraceEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function assignAttributes()
$parsed = $this->parser->parseTraceEntry($this->content);

foreach ($parsed as $key => $value) {
$this->{$key} = $value;
$this->{$key} = str_replace('\\\\', '\\', $value);
}
}
}
36 changes: 24 additions & 12 deletions src/Jackiedo/LogReader/LogParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class LogParser implements LogParserInterface
const LOG_DATE_PATTERN = "\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\]";
const LOG_ENVIRONMENT_PATTERN = "(\w+)";
const LOG_LEVEL_PATTERN = "([A-Z]+)";
const CONTEXT_EXCEPTION_PATTERN = "((exception\s\')?([^\s\']+)(\'|\:)\s+)?";
const CONTEXT_MESSAGE_PATTERN = "(with\smessage\s)?(.*)?";
const CONTEXT_IN_PATTERN = "\sin\s(.*)\:(\d+)";
const CONTEXT_MESSAGE_PATTERN = "([^\{]*)?";
const CONTEXT_EXCEPTION_PATTERN = "(\{\"exception\"\:\"\[object\]\s\(([^\s\(]+))?.*";
const CONTEXT_IN_PATTERN = "\s(in|at)\s(.*)\:(\d+)\)?";
const STACK_TRACE_DIVIDER_PATTERN = "(\[stacktrace\]|Stack trace\:)";
const STACK_TRACE_INDEX_PATTERN = "\#\d+\s";
const TRACE_IN_DIVIDER_PATTERN = "\:\s";
Expand Down Expand Up @@ -69,6 +69,9 @@ public function parseLogBody($content)
$context = $parts[0];
$stack_traces = (isset($parts[1])) ? $parts[1] : null;

// Delete the last unnecessary line of stack_traces
$stack_traces = preg_match("/^(.*)\"\}\s*$/ms", $stack_traces, $match) ? $match[1] : $stack_traces;

return compact('context', 'stack_traces');
}

Expand All @@ -82,17 +85,26 @@ public function parseLogBody($content)
public function parseLogContext($content)
{
$content = trim($content);
$pattern = "/^".self::CONTEXT_EXCEPTION_PATTERN.self::CONTEXT_MESSAGE_PATTERN.self::CONTEXT_IN_PATTERN."$/ms";
$pattern = "/^".self::CONTEXT_MESSAGE_PATTERN.self::CONTEXT_EXCEPTION_PATTERN.self::CONTEXT_IN_PATTERN."$/ms";

preg_match($pattern, $content, $matchs);

$exception = isset($matchs[1]) ? $matchs[3] : null;
$message = isset($matchs[6]) ? $matchs[6] : $content;
$in = isset($matchs[7]) ? $matchs[7] : null;
$line = isset($matchs[8]) ? $matchs[8] : null;
$message = isset($matchs[1]) ? trim($matchs[1]) : trim($content);
$exception = isset($matchs[2]) ? trim($matchs[3]) : null;
$in = isset($matchs[5]) ? trim($matchs[5]) : null;
$line = isset($matchs[6]) ? trim($matchs[6]) : null;

// if exception is not exist, it may be placed before message
if (! $exception) {
$pattern = "/^((exception\s\')?([^\s\']+)(\'|\:))?(\swith\smessage\s)?(.*)$/ms";

// Strip quote chars from the beginning and end of message
$message = preg_match("/^\'(.*)\'$/ms", $message, $matchQuote) ? $matchQuote[1] : $message;
unset($matchs);
preg_match($pattern, $message, $matchs);

$exception = isset($matchs[1]) ? trim($matchs[3]) : null;
$message = isset($matchs[6]) ? trim($matchs[6]) : trim($content);
$message = preg_match("/^\'(.*)\'$/ms", $message, $trimmedQuote) ? $trimmedQuote[1] : $message;
}

return compact('message', 'exception', 'in', 'line');
}
Expand All @@ -115,7 +127,7 @@ public function parseStackTrace($content)

$traces = preg_split($pattern, $content);

if (empty($trace[0])) {
if (empty($traces[0])) {
array_shift($traces);
}

Expand All @@ -139,7 +151,7 @@ public function parseTraceEntry($content)
if (!empty($content) && preg_match("/.*".self::TRACE_IN_DIVIDER_PATTERN.".*/", $content)) {
$split = array_map('trim', preg_split("/".self::TRACE_IN_DIVIDER_PATTERN."/", $content));

$in = trim($split[0]);
$in = trim($split[0]);
$caught_at = (isset($split[1])) ? $split[1] : null;

if (preg_match("/^".self::TRACE_FILE_PATTERN."$/", $in, $matchs)) {
Expand Down

0 comments on commit 8782d83

Please sign in to comment.