Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepend [Scout] to all log messages for Scout #93

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Logger/FilteredLogLevelDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ final class FilteredLogLevelDecorator implements LoggerInterface
{
use LoggerTrait;

private const PREPEND_SCOUT_TAG = '[Scout] ';

private const LOG_LEVEL_ORDER = [
LogLevel::DEBUG => 0,
LogLevel::INFO => 1,
Expand Down Expand Up @@ -52,6 +54,6 @@ public function log($level, $message, array $context = [])
return;
}

$this->realLogger->log($level, $message, $context);
$this->realLogger->log($level, self::PREPEND_SCOUT_TAG . $message, $context);
}
}
6 changes: 5 additions & 1 deletion tests/Unit/AgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public function testLogMessagesAreLoggedWhenUsingDefaultConfiguration() : void

$logger->expects(self::once())
->method('log')
->with(LogLevel::DEBUG, 'Scout Core Agent Connected', []);
->with(
LogLevel::DEBUG,
self::stringContains('Scout Core Agent Connected'),
[]
);

$config = new Config();
$config->set(ConfigKey::MONITORING_ENABLED, 'false');
Expand Down
26 changes: 25 additions & 1 deletion tests/Unit/Logger/FilteredLogLevelDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/** @covers \Scoutapm\Logger\FilteredLogLevelDecorator */
final class FilteredLogLevelDecoratorTest extends TestCase
{
private const PREPEND_SCOUT_TAG = '[Scout] ';

/** @var LoggerInterface&MockObject */
private $decoratedLogger;

Expand All @@ -26,6 +28,24 @@ public function setUp() : void
$this->decoratedLogger = $this->createMock(LoggerInterface::class);
}

public function testLogMessagesHaveScoutTagPrepended() : void
{
$decorator = new FilteredLogLevelDecorator($this->decoratedLogger, LogLevel::DEBUG);

$logMessage = uniqid('logMessage', true);

$this->decoratedLogger
->expects(self::once())
->method('log')
->with(
LogLevel::DEBUG,
self::PREPEND_SCOUT_TAG . $logMessage,
[]
);

$decorator->debug($logMessage);
}

public function testLogMessagesBelowThresholdAreNotLogged() : void
{
$decorator = new FilteredLogLevelDecorator($this->decoratedLogger, LogLevel::NOTICE);
Expand All @@ -47,7 +67,11 @@ public function testLogMessagesAboveThresholdAreLogged() : void
$this->decoratedLogger
->expects(self::once())
->method('log')
->with(LogLevel::WARNING, $logMessage, $context);
->with(
LogLevel::WARNING,
self::stringContains($logMessage),
$context
);

$decorator->warning($logMessage, $context);
}
Expand Down