-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.php
More file actions
79 lines (59 loc) · 1.79 KB
/
Log.php
File metadata and controls
79 lines (59 loc) · 1.79 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
class Log
{
private $fileName;
private $handle;
public $currentDate;
public $currentTime;
public function __construct($prefix = 'log')
{
// make a file name and use a string to say log.2016-05-19.log
// $this->filename = "$prefix-$currentDate.log";
$this->setFileName("$prefix-YYYY-MM-DD.log");
// making the connection to the filename specified above
$this->setHandle(fopen($this->fileName, 'a'));
}
public function setFileName($fileName)
{
$this->fileName = (string)$fileName;
}
public function setHandle($handle)
{
$this->handle = $handle;
}
public function getFileName()
{
return $this->fileName;
}
public function getHandle()
{
return $this->handle;
}
public function logMessage($logLevel, $message)
{
// get the date
$this->currentDate = date("Y-m-d");
// get the time
$this->currentTime = date('h:i:s');
// use handle for connection
// $currentDate . $currentTime . then "[level]" (this comes from $loglevel)
// $logLevel comes from the first value in the logmessage function, which is INFO or ERROR
fwrite($this->handle, $this->currentDate . ' ' . $this->currentTime . "[$logLevel]" . $message . PHP_EOL);
}
// message will be provided when the function is called!
public function logInfo($message)
{
$this->logMessage("INFO", $message);
}
// message will be provided when the function is called!
public function logError($message)
{
$this->logMessage("ERROR", $message);
}
public function __destruct()
{
fclose($this->handle);
echo "did it work?\n";
}
}
?>