| @@ -1,13 +1,57 @@ | ||
| 1 | 1 | <?php |
| 2 | +// class berqLogs { | |
| 3 | +// private $logFile; | |
| 4 | + | |
| 5 | +// public function __construct() { | |
| 6 | +// $this->logFile = optifer_cache . 'berqwp.log'; | |
| 7 | +// } | |
| 8 | + | |
| 9 | +// public function log($message, $status = 'INFO') { | |
| 10 | +// $timestamp = date('Y-m-d H:i:s'); | |
| 11 | +// $logEntry = "[$timestamp][$status]: $message" . PHP_EOL; | |
| 12 | +// file_put_contents($this->logFile, $logEntry, FILE_APPEND); | |
| 13 | +// } | |
| 14 | + | |
| 15 | +// public function info($message) { | |
| 16 | +// $this->log($message, 'INFO'); | |
| 17 | +// } | |
| 18 | + | |
| 19 | +// public function warning($message) { | |
| 20 | +// $this->log($message, 'WARNING'); | |
| 21 | +// } | |
| 22 | + | |
| 23 | +// public function error($message) { | |
| 24 | +// $this->log($message, 'ERROR'); | |
| 25 | +// } | |
| 26 | +// } | |
| 27 | + | |
| 28 | +// global $berq_log; | |
| 29 | +// $berq_log = new berqLogs(); | |
| 30 | + | |
| 2 | 31 | class berqLogs { |
| 3 | 32 | private $logFile; |
| 33 | + private $logDir; | |
| 34 | + private $maxSize = 1048576 * 20; | |
| 4 | 35 | |
| 5 | 36 | public function __construct() { |
| 6 | - $this->logFile = optifer_cache . 'berqwp.log'; | |
| 37 | + $this->logDir = rtrim(optifer_cache, '/') . '/logs/'; | |
| 38 | + if (!file_exists($this->logDir)) { | |
| 39 | + mkdir($this->logDir, 0755, true); | |
| 40 | + } | |
| 41 | + | |
| 42 | + $this->logFile = $this->logDir . 'berqwp.log'; | |
| 7 | 43 | } |
| 8 | 44 | |
| 45 | + private function checkLogSize() { | |
| 46 | + if (file_exists($this->logFile) && filesize($this->logFile) >= $this->maxSize) { | |
| 47 | + $backup = $this->logDir . 'berqwp_' . date('Ymd_His') . '.log'; | |
| 48 | + rename($this->logFile, $backup); | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 9 | 52 | public function log($message, $status = 'INFO') { |
| 53 | + $this->checkLogSize(); | |
| 10 | 54 | $timestamp = date('Y-m-d H:i:s'); |
| 11 | 55 | $logEntry = "[$timestamp][$status]: $message" . PHP_EOL; |
| 12 | 56 | file_put_contents($this->logFile, $logEntry, FILE_APPEND); |
| 13 | 57 | } |
| @@ -25,5 +69,5 @@ | ||
| 25 | 69 | } |
| 26 | 70 | } |
| 27 | 71 | |
| 28 | 72 | global $berq_log; |
| 29 | -$berq_log = new berqLogs(); | |
| 73 | +$berq_log = new berqLogs(); | |