Skip to content

Commit fe6377d

Browse files
mudrd8mzDavid Castro
authored andcommitted
Add ability to control logging via local_redislock_logging config flag
Resolves #8
1 parent e17bead commit fe6377d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ Provides a Moodle lock factory class for locking with Redis. This plugin was con
99
#Installation
1010
Clone the repository or download and extract the code into the local directory of your Moodle install (e.g. $CFG->wwwroot/local/redislock) and run the site's upgrade script. Set $CFG->local_redislock_redis_server with your Redis server's connection string. Set $CFG->lock_factory to '\\\\local_redislock\\\\lock\\\\redis_lock_factory' in your config file.
1111

12+
Use the boolean flag `$CFG->local_redislock_logging` to control whether verbose
13+
logging should be emitted. If not set, logging is automatically-enabled when running
14+
in the CLI environment with debugging enabled on `DEBUG_NORMAL` level at least.

classes/lock/redis_lock_factory.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,30 @@ class redis_lock_factory implements lock_factory {
5656
protected $openlocks = [];
5757

5858
/**
59-
* @var boolean Enables logging
59+
* @var boolean Should verbose logs be emitted.
6060
*/
6161
protected $logging;
6262

6363
/**
6464
* @param string $type The type this lock is used for (e.g. cron, cache).
6565
* @param \Redis|null $redis An instance of the PHPRedis extension class.
66-
* @param boolean|null $logging Enables logging
66+
* @param boolean|null $logging Should verbose logs be emitted.
6767
* @throws \coding_exception
6868
*/
6969
public function __construct($type, \Redis $redis = null, $logging = null) {
70+
global $CFG;
71+
7072
$this->type = $type;
7173

7274
if (is_null($redis)) {
7375
$redis = $this->bootstrap_redis();
7476
}
7577
if (is_null($logging)) {
76-
$logging = (CLI_SCRIPT && debugging() && !PHPUNIT_TEST);
78+
if (isset($CFG->local_redislock_logging)) {
79+
$logging = (bool) $CFG->local_redislock_logging;
80+
} else {
81+
$logging = (CLI_SCRIPT && debugging() && !PHPUNIT_TEST);
82+
}
7783
}
7884
$this->redis = $redis;
7985
$this->logging = $logging;

0 commit comments

Comments
 (0)