-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedisMode.php
More file actions
47 lines (42 loc) · 1.14 KB
/
RedisMode.php
File metadata and controls
47 lines (42 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace WebmanTech\Logger\Mode;
use InvalidArgumentException;
use Monolog\Handler\RedisHandler;
class RedisMode extends BaseMode
{
/**
* @var array
*/
protected $config = [
'redis' => null,
'redis_key_prefix' => 'webmanLog:',
'redis_size' => 0,
];
/**
* @inheritDoc
*/
public function getHandler(string $channelName, string $level): array
{
if (!$this->checkHandlerUsefulForChannel($channelName)) {
return [];
}
$redis = $this->config['redis'];
if (is_callable($redis)) {
$redis = call_user_func($redis);
}
if (!$redis) {
throw new InvalidArgumentException('redis 配置错误');
}
return [
'class' => RedisHandler::class,
'constructor' => [
'redis' => $redis,
'key' => $this->config['redis_key_prefix'] . $channelName,
'level' => $level,
'bubble' => true,
'capSize' => $this->config['redis_size'],
],
'formatter' => $this->getFormatter(),
];
}
}