1 | <?php |
||
17 | class SimpleLogger extends BasicLogger |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * The log file path |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | private $file = null; |
||
26 | |||
27 | /** |
||
28 | * The maximum log file size in megabyte |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | private $maxLogSize; |
||
33 | |||
34 | /** |
||
35 | * Create a new SimpleLogger instance |
||
36 | * |
||
37 | * @param string $logFilePath |
||
38 | * The path to the log file. |
||
39 | * @param int $maxLogSize |
||
40 | * The maximum log file size before it is rotated. |
||
41 | */ |
||
42 | 16 | public function __construct($logFilePath = 'application.log', $maxLogSize = 2) |
|
51 | |||
52 | /** |
||
53 | * This function provides the real logging function. |
||
54 | * |
||
55 | * First the log file size is checked. |
||
56 | * When the maximum size has reached, the file will be overwritten. |
||
57 | * Otherwise the log string is appended. |
||
58 | * |
||
59 | * @param integer $level |
||
60 | * The arbitrary level |
||
61 | * @param string $message |
||
62 | * The message to log |
||
63 | * @param array $context |
||
64 | * The context of logging |
||
65 | */ |
||
66 | 15 | protected function logImpl($level, $message, array $context = array()) |
|
83 | |||
84 | /** |
||
85 | * Checks whether a rotation of log file is necessary |
||
86 | * |
||
87 | * @return boolean true in case of its necessary, false otherwise |
||
88 | */ |
||
89 | 15 | private function isRotationNeeded() |
|
107 | |||
108 | /** |
||
109 | * Retrieve the file name of logger |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | 14 | public function getFile() |
|
117 | |||
118 | /** |
||
119 | * Retrieve the maximum size of log file in megabytes |
||
120 | * |
||
121 | * @return int |
||
122 | */ |
||
123 | 1 | public function getMaxLogSize() |
|
127 | } |
||
128 |