Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <tsteur@users.noreply.github.com>2018-04-12 07:27:47 +0300
committerBenaka <diosmosis@users.noreply.github.com>2018-04-12 07:27:47 +0300
commit6b42db96c01c5b1357c42c1de1655ba4114a9d3e (patch)
treed63ddccdfff327bfcb2967f0de22ee0754cf50ef /plugins/Monolog
parentc5fc11d125cf1c8495f043e6b429d9ff0e34967a (diff)
Log a job ID for cli commands (#12717)
* log requestId for cli commands * format console log * log pid for cli commands * fix test
Diffstat (limited to 'plugins/Monolog')
-rw-r--r--plugins/Monolog/Processor/RequestIdProcessor.php10
-rw-r--r--plugins/Monolog/config/cli.php2
-rw-r--r--plugins/Monolog/tests/Integration/LogTest.php14
3 files changed, 13 insertions, 13 deletions
diff --git a/plugins/Monolog/Processor/RequestIdProcessor.php b/plugins/Monolog/Processor/RequestIdProcessor.php
index f36568193a..3dd01cb827 100644
--- a/plugins/Monolog/Processor/RequestIdProcessor.php
+++ b/plugins/Monolog/Processor/RequestIdProcessor.php
@@ -19,12 +19,12 @@ class RequestIdProcessor
public function __invoke(array $record)
{
- if (Common::isPhpCliMode()) {
- return $record;
- }
-
if (empty($this->currentRequestKey)) {
- $this->currentRequestKey = substr(Common::generateUniqId(), 0, 5);
+ if (Common::isPhpCliMode()) {
+ $this->currentRequestKey = getmypid();
+ } else {
+ $this->currentRequestKey = substr(Common::generateUniqId(), 0, 5);
+ }
}
$record['extra']['request_id'] = $this->currentRequestKey;
diff --git a/plugins/Monolog/config/cli.php b/plugins/Monolog/config/cli.php
index 04bf1cdbca..0b33f04c7b 100644
--- a/plugins/Monolog/config/cli.php
+++ b/plugins/Monolog/config/cli.php
@@ -24,6 +24,6 @@ return array(
$handler->setFormatter(new ConsoleFormatter($c->get('log.console.format'), null, true, true));
return $handler;
},
- 'log.console.format' => '%start_tag%%level_name% [%datetime%]%end_tag% %message%' . PHP_EOL,
+ 'log.console.format' => '%start_tag%%level_name% [%datetime%] %extra.request_id% %end_tag% %message%' . PHP_EOL,
);
diff --git a/plugins/Monolog/tests/Integration/LogTest.php b/plugins/Monolog/tests/Integration/LogTest.php
index 75a8166d4f..0389b504f0 100644
--- a/plugins/Monolog/tests/Integration/LogTest.php
+++ b/plugins/Monolog/tests/Integration/LogTest.php
@@ -26,12 +26,12 @@ class LogTest extends IntegrationTestCase
{
const TESTMESSAGE = 'test%smessage';
const STRING_MESSAGE_FORMAT = '[%tag%] %message%';
- const STRING_MESSAGE_FORMAT_SPRINTF = "[%s] %s";
+ const STRING_MESSAGE_FORMAT_SPRINTF = "[%s] [%s] %s";
- public static $expectedExceptionOutput = '[Monolog] LogTest.php(112): dummy error message
+ public static $expectedExceptionOutput = '[Monolog] [%s] LogTest.php(112): dummy error message
dummy backtrace';
- public static $expectedErrorOutput = '[Monolog] dummyerrorfile.php(145): Unknown error (102) - dummy error string
+ public static $expectedErrorOutput = '[Monolog] [%s] dummyerrorfile.php(145): Unknown error (102) - dummy error string
dummy backtrace';
public function setUp()
@@ -99,7 +99,7 @@ class LogTest extends IntegrationTestCase
$error = new \ErrorException("dummy error string", 0, 102, "dummyerrorfile.php", 145);
Log::error($error);
- $this->checkBackend($backend, self::$expectedErrorOutput, $formatMessage = false, $tag = 'Monolog');
+ $this->checkBackend($backend, sprintf(self::$expectedErrorOutput, getmypid()), $formatMessage = false, $tag = 'Monolog');
}
/**
@@ -112,7 +112,7 @@ class LogTest extends IntegrationTestCase
$exception = new Exception("dummy error message");
Log::error($exception);
- $this->checkBackend($backend, self::$expectedExceptionOutput, $formatMessage = false, $tag = 'Monolog');
+ $this->checkBackend($backend, sprintf(self::$expectedExceptionOutput, getmypid()), $formatMessage = false, $tag = 'Monolog');
}
/**
@@ -192,7 +192,7 @@ class LogTest extends IntegrationTestCase
private function checkBackend($backend, $expectedMessage, $formatMessage = false, $tag = false)
{
if ($formatMessage) {
- $expectedMessage = sprintf(self::STRING_MESSAGE_FORMAT_SPRINTF, $tag, $expectedMessage);
+ $expectedMessage = sprintf(self::STRING_MESSAGE_FORMAT_SPRINTF, $tag, getmypid(), $expectedMessage);
}
if ($backend == 'file') {
@@ -201,7 +201,7 @@ class LogTest extends IntegrationTestCase
$fileContents = file_get_contents(self::getLogFileLocation());
$fileContents = $this->removePathsFromBacktrace($fileContents);
- $expectedMessage = str_replace("\n ", "\n[Monolog]", $expectedMessage);
+ $expectedMessage = str_replace("\n ", "\n[Monolog] [" . getmypid() . "]", $expectedMessage);
$this->assertEquals($expectedMessage . "\n", $fileContents);
} else if ($backend == 'database') {