-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.php
More file actions
51 lines (47 loc) · 1.47 KB
/
Log.php
File metadata and controls
51 lines (47 loc) · 1.47 KB
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
47
48
49
50
<?php
class Log
{
private $filename;
private $handle;
public function __construct($prefix)
{
$currentDate = date('Y-m-d');
$this->setFilename($prefix);
$this->setHandle();
}
public function setFilename ($prefix) {
$this->filename = $prefix . "log-{$currentDate}.log";
}
public function setHandle () {
$this->handle = fopen($this->filename, 'a');
}
public function __destruct()
{
fclose($this->handle);
}
//level is "awareness" message for yourself and level of importance
public function logMessage($logLevel, $message)
{
//this is calling the method nameFile so you dont have to REWRITE so to speak to be "more functional"
// $this->nameFile();
// //setting the files name to a variable
// $this->filename = "log-{$currentDate}.log";
$currentDateTime = date('Y-m-d h:i:s=T');
fwrite($this->handle, PHP_EOL . $currentDateTime . " " . "[" . $logLevel ."]" . " " . $message);
// fwrite($handle, $messageDisplayed . PHP_EOL);
}
public function info($message)
{
$this->logMessage("INFO:", $message);
}
public function error($message)
{
$this->logMessage("ERROR:", $message);
}
// public function nameFile()
// {
// $currentDate = date('Y-m-d');
// //setting the files name to a variable
// $this->filename = "log-{$currentDate}.log";
// }
}