Skip to content

Commit

Permalink
Merge pull request #32 from JackieDo/version-2.x
Browse files Browse the repository at this point in the history
Upgrade features
  • Loading branch information
JackieDo authored Apr 9, 2020
2 parents 9acf462 + 076af1b commit f013c00
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
}
],
"require": {
"illuminate/cache": "5.*",
"illuminate/config": "5.*",
"illuminate/console": "5.*",
"illuminate/http": "5.*",
"illuminate/pagination": "5.*",
"illuminate/support": "5.*",
"nesbot/carbon": "~1.20 || ^2.0"
"illuminate/cache": "^6.0|5.*",
"illuminate/config": "^6.0|5.*",
"illuminate/console": "^6.0|5.*",
"illuminate/http": "^6.0|5.*",
"illuminate/pagination": "^6.0|5.*",
"illuminate/support": "^6.0|5.*",
"nesbot/carbon": "^2.0|~1.20"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 4 additions & 2 deletions src/Jackiedo/LogReader/LogParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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\'{1})?([^\s\']+)(\'{1}|\:)\s+)?";
const CONTEXT_EXCEPTION_PATTERN = "((exception\s\')?([^\s\']+)(\'|\:)\s+)?";
const CONTEXT_MESSAGE_PATTERN = "(with\smessage\s)?(.*)?";
const CONTEXT_IN_PATTERN = "\sin\s(.*)\:(\d+)";
const STACK_TRACE_DIVIDER_PATTERN = "(\[stacktrace\]|Stack trace\:)";
Expand Down Expand Up @@ -88,10 +88,12 @@ public function parseLogContext($content)

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

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

return compact('message', 'exception', 'in', 'line');
}

Expand Down
10 changes: 10 additions & 0 deletions src/Jackiedo/LogReader/LogReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ public function __construct(Cache $cache, Config $config, Request $request)
$this->levelable = new Levelable;
$this->parser = new LogParser;

$defaultParserClass = $this->config->get('log-reader.default_log_parser', null);

if (class_exists($defaultParserClass)) {
$logParser = new $defaultParserClass;

if ($logParser instanceof LogParserInterface) {
$this->parser = new $logParser;
}
}

$this->setLogPath($this->config->get('log-reader.path', storage_path('logs')));
$this->setLogFilename($this->config->get('log-reader.filename', 'laravel.log'));
$this->setEnvironment($this->config->get('log-reader.environment'));
Expand Down
16 changes: 15 additions & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@
|
*/

'order_by_direction' => 'asc'
'order_by_direction' => 'asc',

/*
|--------------------------------------------------------------------------
| Default log parser
|--------------------------------------------------------------------------
|
| This is the default class used to parse log entries.
|
| If this setting is not set, the 'Jackiedo\LogReader\LogParser' class will
| be used.
|
*/

'default_log_parser' => null

);

0 comments on commit f013c00

Please sign in to comment.