| 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 |
|
| 31 |
class berqLogs { |
| 32 |
private $logFile; |
| 33 |
private $logDir; |
| 34 |
private $maxSize = 1048576 * 20; |
| 35 |
|
| 36 |
public function __construct() { |
| 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'; |
| 43 |
} |
| 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 |
|
| 52 |
public function log($message, $status = 'INFO') { |
| 53 |
$this->checkLogSize(); |
| 54 |
$timestamp = date('Y-m-d H:i:s'); |
| 55 |
$logEntry = "[$timestamp][$status]: $message" . PHP_EOL; |
| 56 |
file_put_contents($this->logFile, $logEntry, FILE_APPEND); |
| 57 |
} |
| 58 |
|
| 59 |
public function info($message) { |
| 60 |
$this->log($message, 'INFO'); |
| 61 |
} |
| 62 |
|
| 63 |
public function warning($message) { |
| 64 |
$this->log($message, 'WARNING'); |
| 65 |
} |
| 66 |
|
| 67 |
public function error($message) { |
| 68 |
$this->log($message, 'ERROR'); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
global $berq_log; |
| 73 |
$berq_log = new berqLogs(); |
| 74 |
|