1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Eccube\ServiceProvider; |
4
|
|
|
|
5
|
|
|
use Eccube\EventListener\LogListener; |
6
|
|
|
use Eccube\Log\Logger; |
7
|
|
|
use Eccube\Log\Monolog\Helper\LogHelper; |
8
|
|
|
use Silex\Application; |
9
|
|
|
use Silex\ServiceProviderInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class LogServiceProvider |
13
|
|
|
* |
14
|
|
|
* @package Eccube\ServiceProvider |
15
|
|
|
*/ |
16
|
|
|
class LogServiceProvider implements ServiceProviderInterface |
17
|
|
|
{ |
18
|
1195 |
|
public function register(Application $app) |
19
|
|
|
{ |
20
|
1195 |
|
$app->register(new \Silex\Provider\MonologServiceProvider()); |
21
|
|
|
|
22
|
|
|
// Log |
23
|
|
|
$app['eccube.logger'] = $app->share(function ($app) { |
24
|
1192 |
|
return new Logger($app); |
25
|
1195 |
|
}); |
26
|
|
|
|
27
|
|
|
// ヘルパー作成 |
28
|
|
|
$app['eccube.monolog.helper'] = $app->share(function ($app) { |
29
|
1193 |
|
return new LogHelper($app); |
30
|
1195 |
|
}); |
31
|
|
|
|
32
|
|
|
// ログクラス作成ファクトリー |
33
|
|
|
$app['eccube.monolog.factory'] = $app->protect(function (array $channelValues) use ($app) { |
34
|
|
|
|
35
|
574 |
|
$log = new $app['monolog.logger.class']($channelValues['name']); |
|
|
|
|
36
|
|
|
|
37
|
|
|
// EccubeMonologHelper内でHandlerを設定している |
38
|
574 |
|
$log->pushHandler($app['eccube.monolog.helper']->getHandler($channelValues)); |
39
|
|
|
|
40
|
574 |
|
return $log; |
41
|
1195 |
|
}); |
42
|
|
|
|
43
|
|
|
// チャネルに応じてログを作成し、フロント、管理、プラグイン用のログ出力クラスを作成 |
44
|
1195 |
|
$channels = $app['config']['log']['channel']; |
45
|
|
|
// monologの設定は除外 |
46
|
1195 |
|
unset($channels['monolog']); |
47
|
1195 |
|
foreach ($channels as $channel => $channelValues) { |
48
|
|
|
$app['monolog.logger.'.$channel] = $app->share(function ($app) use ($channelValues) { |
49
|
574 |
|
return $app['eccube.monolog.factory']($channelValues); |
50
|
1195 |
|
}); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// MonologServiceProviderで定義されているmonolog.handlerの置換 |
54
|
1195 |
|
$channelValues = $app['config']['log']['channel']['monolog']; |
55
|
1195 |
|
$app['monolog.name'] = $channelValues['name']; |
56
|
|
|
$app['monolog.handler'] = $app->share(function ($app) use ($channelValues) { |
57
|
1193 |
|
return $app['eccube.monolog.helper']->getHandler($channelValues); |
58
|
1195 |
|
}); |
59
|
|
|
|
60
|
|
|
$app['eccube.monolog.listener'] = $app->share(function () use ($app) { |
61
|
1192 |
|
return new LogListener($app['eccube.logger']); |
62
|
1195 |
|
}); |
63
|
|
|
|
64
|
1195 |
|
$app['listener.requestdump'] = $app->share(function ($app) { |
65
|
1192 |
|
return new \Eccube\EventListener\RequestDumpListener($app); |
66
|
1195 |
|
}); |
67
|
|
|
} |
68
|
|
|
|
69
|
1192 |
|
public function boot(Application $app) |
70
|
|
|
{ |
71
|
1192 |
|
$app['dispatcher']->addSubscriber($app['listener.requestdump']); |
72
|
1192 |
|
$app['dispatcher']->addSubscriber($app['eccube.monolog.listener']); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|