-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.php
More file actions
46 lines (29 loc) · 965 Bytes
/
Log.php
File metadata and controls
46 lines (29 loc) · 965 Bytes
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
39
40
41
42
43
44
45
46
<?php
class Log
{
public $fileName;
public $handle;
public $date;
public $time;
// The logMessage function will never be manipulated directly, it's just used by logError and logInfo
public function logMessage($logLevel,$message){
fwrite($this->handle, PHP_EOL . $this->date . $this->time . " " . $logLevel . ":" . $message);
}
// Both logError and log Info take in a message and add the appropriate level
public function logError($message){
$this->logMessage("ERROR", $message);
}
public function logInfo($message){
$this->logMessage("INFO", $message);
}
// Construct is used to to create the variables, it's not manipulated directly
public function __construct($prefix='log-'){
$this->date=date("m-d-o");
$this->fileName=$prefix . $this->date;
$this->handle=fopen($this->fileName, 'a');
$this->time=" " . date("g") . ":" . date("i") . ":" . date("s");
}
public function __destruct(){
fclose($this->handle);
}
}