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