Skip to content

Commit

Permalink
Append channel prefix only once (#29)
Browse files Browse the repository at this point in the history
* delete travis php5.5 job and add test before appending prefix
  • Loading branch information
Deamon authored Oct 7, 2019
1 parent 8d7bcd3 commit 40c52d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ sudo: false

matrix:
include:
- php: 5.5
env: deps=low
- php: 5.6
env: deps=low
- php: 5.6
Expand Down
6 changes: 4 additions & 2 deletions Processors/Monolog/DeamonLoggerExtraWebProcessor.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ private function addUserInfo()

private function addChannelInfo()
{
$this->addInfo('global_channel', $this->record['channel']);
if(!array_key_exists('global_channel', $this->record['extra'])){
$this->addInfo('global_channel', $this->record['channel']);
}

if ($this->channelPrefix !== null) {
if ($this->channelPrefix !== null && substr($this->record['channel'], 0, strlen($this->channelPrefix)) !== $this->channelPrefix) {
$this->record['channel'] = sprintf('%s.%s', $this->channelPrefix, $this->record['channel']);
}
}
Expand Down
17 changes: 15 additions & 2 deletions Tests/Processors/Monolog/DeamonLoggerExtraWebProcessorTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class DeamonLoggerExtraWebProcessorTest extends TestCase
{

public function testProcessorWithNullContainer()
{
$processor = new DeamonLoggerExtraWebProcessor();
Expand Down Expand Up @@ -107,6 +108,18 @@ public function testAddChannelInfoWithChannelPrefix()
$this->assertArrayHasKeyAndEquals('channel', $record, sprintf('prefix.%s', $originalRecord['channel']));
}

public function testAppendChannelPrefixOnlyOnce()
{
$config = $this->getDisplayConfig(['global_channel' => true], 'prefix');
$processor = new DeamonLoggerExtraWebProcessor(new MyContainerForTests(), $config);
$originalRecord = $this->getRecord();
$record = $processor($originalRecord);
$recordReparsed = $processor($record);

$this->assertArrayHasKeyAndEquals('global_channel', $recordReparsed['extra'], $originalRecord['channel'], 'global_channel must be equals to the original channel without any prefix');
$this->assertArrayHasKeyAndEquals('channel', $recordReparsed, sprintf('prefix.%s', $originalRecord['channel']), 'channel must be equals to prefix.channel');
}

protected function getDisplayConfig($trueValues, $channelPrefix = null)
{
$ret = array_merge(
Expand All @@ -133,10 +146,10 @@ protected function getDisplayConfig($trueValues, $channelPrefix = null)
];
}

protected function assertArrayHasKeyAndEquals($key, $array, $value)
protected function assertArrayHasKeyAndEquals($key, $array, $value, $message = null)
{
$this->assertArrayHasKey($key, $array);
$this->assertEquals($value, $array[$key]);
$this->assertEquals($value, $array[$key], $message);
}

/**
Expand Down

0 comments on commit 40c52d5

Please sign in to comment.