1 | <?php |
||
5 | class Logger |
||
6 | { |
||
7 | const LOG_ERROR = 'error'; |
||
8 | const LOG_DEPRECATED = 'deprecated'; |
||
9 | const LOG_DEBUG = 'debug'; |
||
10 | |||
11 | /** @var Logger[] */ |
||
12 | static protected $instances; |
||
13 | |||
14 | /** @var string what kind of log is this */ |
||
15 | protected $facility; |
||
16 | |||
17 | protected $isLogging = true; |
||
18 | |||
19 | /** |
||
20 | * Logger constructor. |
||
21 | * |
||
22 | * @param string $facility The type of log |
||
23 | */ |
||
24 | protected function __construct($facility) |
||
34 | |||
35 | /** |
||
36 | * Return a Logger instance for the given facility |
||
37 | * |
||
38 | * @param string $facility The type of log |
||
39 | * @return Logger |
||
40 | */ |
||
41 | static public function getInstance($facility = self::LOG_ERROR) |
||
48 | |||
49 | /** |
||
50 | * Convenience method to directly log to the error log |
||
51 | * |
||
52 | * @param string $message The log message |
||
53 | * @param mixed $details Any details that should be added to the log entry |
||
54 | * @param string $file A source filename if this is related to a source position |
||
55 | * @param int $line A line number for the above file |
||
56 | * @return bool has a log been written? |
||
57 | */ |
||
58 | static public function error($message, $details = null, $file = '', $line = 0) |
||
64 | |||
65 | /** |
||
66 | * Convenience method to directly log to the debug log |
||
67 | * |
||
68 | * @param string $message The log message |
||
69 | * @param mixed $details Any details that should be added to the log entry |
||
70 | * @param string $file A source filename if this is related to a source position |
||
71 | * @param int $line A line number for the above file |
||
72 | * @return bool has a log been written? |
||
73 | */ |
||
74 | static public function debug($message, $details = null, $file = '', $line = 0) |
||
80 | |||
81 | /** |
||
82 | * Convenience method to directly log to the deprecation log |
||
83 | * |
||
84 | * @param string $message The log message |
||
85 | * @param mixed $details Any details that should be added to the log entry |
||
86 | * @param string $file A source filename if this is related to a source position |
||
87 | * @param int $line A line number for the above file |
||
88 | * @return bool has a log been written? |
||
89 | */ |
||
90 | static public function deprecated($message, $details = null, $file = '', $line = 0) |
||
96 | |||
97 | /** |
||
98 | * Log a message to the facility log |
||
99 | * |
||
100 | * @param string $message The log message |
||
101 | * @param mixed $details Any details that should be added to the log entry |
||
102 | * @param string $file A source filename if this is related to a source position |
||
103 | * @param int $line A line number for the above file |
||
104 | * @return bool has a log been written? |
||
105 | */ |
||
106 | public function log($message, $details = null, $file = '', $line = 0) |
||
136 | |||
137 | /** |
||
138 | * Construct the log file for the given day |
||
139 | * |
||
140 | * @param false|string|int $date Date to access, false for today |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getLogfile($date = false) |
||
152 | |||
153 | /** |
||
154 | * Write the given lines to today's facility log |
||
155 | * |
||
156 | * @param string[] $lines the raw lines to append to the log |
||
157 | * @return bool true if the log was written |
||
158 | */ |
||
159 | protected function writeLogLines($lines) |
||
164 | } |
||
165 |