-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically set redis
log_level
to 7 (#5)
Dynamically set redis `log_level` to 7
- Loading branch information
1 parent
dc1c559
commit 4f7d4ba
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Ampersand\VerboseLogRequest\Plugin; | ||
|
||
use Ampersand\VerboseLogRequest\Service\IsVerbose; | ||
use Magento\Framework\Session\SaveHandler\Redis\Config as RedisConfig; | ||
|
||
class AdjustRedisLogLevel | ||
{ | ||
/** | ||
* @var IsVerbose | ||
*/ | ||
private IsVerbose $isVerbose; | ||
|
||
/** | ||
* @param IsVerbose $isVerbose | ||
*/ | ||
public function __construct( | ||
IsVerbose $isVerbose | ||
) { | ||
$this->isVerbose = $isVerbose; | ||
} | ||
|
||
/** | ||
* Bump redis log level to 7 when on a verbose request. | ||
* | ||
* @param RedisConfig $subject | ||
* @param string $result | ||
* @return mixed|string | ||
*/ | ||
public function afterGetLogLevel(RedisConfig $subject, $result) | ||
{ | ||
if ($this->isVerbose->isVerbose()) { | ||
/** | ||
* 7 (debug: the most information for development/testing) | ||
* | ||
* @link https://github.com/colinmollenhour/Cm_RedisSession#configuration-example | ||
*/ | ||
return '7'; | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Ampersand\VerboseLogRequest\Test\Integration; | ||
|
||
use Ampersand\VerboseLogRequest\Service\IsVerbose\Storage; | ||
use Magento\Framework\Session\SaveHandler\Redis\Config as RedisConfig; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RedisLogLevelTest extends TestCase | ||
{ | ||
public function testGetDefaultLogLevel() | ||
{ | ||
$redisConfig = Bootstrap::getObjectManager()->get(RedisConfig::class); | ||
$this->assertNull($redisConfig->getLogLevel(), 'Default log level is not null'); | ||
} | ||
|
||
public function testGetVerboseLogLevel() | ||
{ | ||
Storage::setFlag(true, true); | ||
$redisConfig = Bootstrap::getObjectManager()->get(RedisConfig::class); | ||
$this->assertEquals('7', $redisConfig->getLogLevel(), 'Default log level is not 7'); | ||
Storage::reset(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters