|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of tenside/core-bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Christian Schiffler <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* This project is provided in good faith and hope to be usable by anyone. |
|
12
|
|
|
* |
|
13
|
|
|
* @package tenside/core-bundle |
|
14
|
|
|
* @author Christian Schiffler <[email protected]> |
|
15
|
|
|
* @copyright 2015 Christian Schiffler <[email protected]> |
|
16
|
|
|
* @license https://github.com/tenside/core-bundle/blob/master/LICENSE MIT |
|
17
|
|
|
* @link https://github.com/tenside/core-bundle |
|
18
|
|
|
* @filesource |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Tenside\CoreBundle\DependencyInjection\Factory; |
|
22
|
|
|
|
|
23
|
|
|
use Monolog\Handler\RotatingFileHandler; |
|
24
|
|
|
use Monolog\Logger; |
|
25
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* This class creates a logger instance. |
|
29
|
|
|
* |
|
30
|
|
|
* @internal |
|
31
|
|
|
*/ |
|
32
|
|
|
class LoggerFactory |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* Create the logger service. |
|
36
|
|
|
* |
|
37
|
|
|
* @param Kernel $kernel The kernel to retrieve the log dir from. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $filename The filename. |
|
40
|
|
|
* |
|
41
|
|
|
* @param int $maxFiles The maximal amount of files to keep (0 means unlimited). |
|
42
|
|
|
* |
|
43
|
|
|
* @param int $level The minimum logging level at which this handler will be triggered. |
|
44
|
|
|
* |
|
45
|
|
|
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not. |
|
46
|
|
|
* |
|
47
|
|
|
* @param int|null $filePermission Optional file permissions (default (0644) are only for owner read/write). |
|
48
|
|
|
* |
|
49
|
|
|
* @param bool $useLocking Try to lock log file before doing any writes. |
|
50
|
|
|
* |
|
51
|
|
|
* @return RotatingFileHandler |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function create( |
|
54
|
|
|
$kernel, |
|
55
|
|
|
$filename, |
|
56
|
|
|
$maxFiles = 0, |
|
57
|
|
|
$level = Logger::DEBUG, |
|
58
|
|
|
$bubble = true, |
|
59
|
|
|
$filePermission = null, |
|
60
|
|
|
$useLocking = false |
|
61
|
|
|
) { |
|
62
|
|
|
return new RotatingFileHandler( |
|
63
|
|
|
$kernel->getLogDir() . DIRECTORY_SEPARATOR . $filename, |
|
64
|
|
|
$maxFiles, |
|
65
|
|
|
$level, |
|
66
|
|
|
$bubble, |
|
67
|
|
|
$filePermission, |
|
68
|
|
|
$useLocking |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|