1 | <?php |
||
16 | class Logger { |
||
17 | |||
18 | /** |
||
19 | * Log messages types constants. |
||
20 | */ |
||
21 | const LOG_INFO = "info"; |
||
22 | const LOG_DEBUG = "debug"; |
||
23 | const LOG_SUCCESS = "success"; |
||
24 | const LOG_WARNING = "warning"; |
||
25 | const LOG_ERROR = "error"; |
||
26 | |||
27 | /** |
||
28 | * Log messages output directions constants. |
||
29 | */ |
||
30 | const TO_OUTPUT_STREAM = 0; |
||
31 | const TO_FILE = 1; |
||
32 | const TO_DB = 2; |
||
33 | |||
34 | /** |
||
35 | * Log messages output direction. |
||
36 | * |
||
37 | * @var int |
||
38 | */ |
||
39 | private $direction = null; |
||
40 | |||
41 | /** |
||
42 | * Log file name. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $fileName = null; |
||
47 | |||
48 | /** |
||
49 | * Log DB object. Object must have log() method for logging functionality |
||
50 | * support. |
||
51 | * |
||
52 | * @var \Asymptix\db\DBObject |
||
53 | */ |
||
54 | private $dbObject = null; |
||
55 | |||
56 | /** |
||
57 | * Initiates Logger setting and starts logging. |
||
58 | * |
||
59 | * @param int $direction Output direction. |
||
60 | * @param mixed $output Output file name or DB object. |
||
61 | * |
||
62 | * @throws LoggerException |
||
63 | */ |
||
64 | public function __construct($direction = null, $output = null) { |
||
83 | |||
84 | /** |
||
85 | * Performs preparation to the logging process. |
||
86 | * |
||
87 | * @throws LoggerException |
||
88 | */ |
||
89 | public function start() { |
||
122 | |||
123 | /** |
||
124 | * Main logging method, performs log writing. |
||
125 | * |
||
126 | * @param int $type Log message type. |
||
127 | * @param string $message Message text. |
||
128 | * @param string $format Time label format. |
||
129 | * @param int $time Timestamp. |
||
130 | * |
||
131 | * @throws LoggerException |
||
132 | */ |
||
133 | public function log($type, $message, $format = "\[Y-m-d H:i:s\]", $time = null) { |
||
182 | |||
183 | /** |
||
184 | * Terminal logging method, performs log to the terminal (CLI). |
||
185 | * |
||
186 | * @param string $message Log message text. |
||
187 | * @param string $timeFormat Time label format. |
||
188 | * @param int $time Timestamp. |
||
189 | */ |
||
190 | public static function terminal($message, $timeFormat = "\[Y-m-d H:i:s\]", $time = null) { |
||
201 | |||
202 | /** |
||
203 | * Closes Logger session. |
||
204 | * |
||
205 | * @throws LoggerException |
||
206 | */ |
||
207 | public function close() { |
||
223 | |||
224 | } |
||
225 | |||
227 |