-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.php
More file actions
77 lines (42 loc) · 1.89 KB
/
log.php
File metadata and controls
77 lines (42 loc) · 1.89 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
<?php
///////////////////////////////////////////////////////////////////////////////////////////
// 1. Create a file in your exercises directory called Log.php. The naming here is important; this file will contain a class called Log that will be the wrapper for your logger functions. Filenames for classes should match their class name.
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// 2. In your Log class you will need:
///////////////////////////////////////////////////////////////////////////////////////////
// * A method called logMessage() that will take in a log level and message as before. It will open the file stored in $filename for appending, output the message in the same format as before, and then close the handle.
// function logMessage($logLevel, $message)
// {
// // $year = date(DATE_ATOM);
// // * A property called $filename where you store the name of the file for the log.
// }
// // * Methods info() and error() that will take in a message and forward it on to logMessage() along with the relevant log level.
// class Log
// {
// public $filename;
// public function logInfo() {
// $message = "You should have asked for more Info!";
// } return $this ->todaysDate "{$message}" . PHP_EOL;
// public $filename;
// public function logError() {
// $message = "You should have tried something else!";
// } return $this ->todaysDate . "{$message}" . PHP_EOL;
class Log {
public $filename;
public $datetime;
public $handle;
function logMessage($logLevel, $message)
{
$string = "{$this->$datetime} $logLevel $message" . PHP_EOL;
fwrite($this->handle, $string);
}
function info($message)
{
$this->logMessage("INFO", $message);
}
function error($message)
{
$this->logMessage("ERROR", $message);
}
}