-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.php
38 lines (30 loc) · 831 Bytes
/
logger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
class Log {
private $file;
private $filepath;
function __construct(){
$this->filepath = getcwd().'/logs/log.txt';
// If the log file doesn't exist, create it
if(!file_exists($this->filepath)) {
$this->createLogFile();
}
// If the log file is over 25mb, archive it and start a new one
if(filesize($this->filepath) > 25000000) {
$this->archiveLog();
}
}
public function write($str) {
$d = date('Y-m-d:H:i:s').':: ';
file_put_contents($this->filepath, $d.$str."\n", FILE_APPEND | LOCK_EX);
}
private function createLogFile(){
$this->file = fopen($this->filepath, "w");
fclose($this->file);
}
private function archiveLog() {
$date = date('m-d-Y');
rename($this->filepath, uniqid().$date.'txt');
$this->createLogFile();
}
}
?>