-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEasyLogger.php
76 lines (62 loc) · 1.89 KB
/
EasyLogger.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
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
<?php
/**
* Class EasyLogger
* @author Mark Christian D. Lopez <[email protected]>
*/
class EasyLogger{
private static $showCallerAndLines = true;
/** @var EasyLogger $logger */
private static $logger;
private $file;
function __construct($logFile = 'notification.log'){
$this->file = fopen(BASE_PATH . '/' . $logFile, 'a');
}
private static function instantiate(){
if(!isset(EasyLogger::$logger)) {
EasyLogger::$logger = new EasyLogger();
}
}
public static function quickLog($message){
EasyLogger::instantiate();
if(EasyLogger::$showCallerAndLines) {
$bt = debug_backtrace();
$caller = array_shift($bt);
$debugging = basename($caller['file']) . ':' . $caller['line'];
EasyLogger::$logger->log($debugging);
}
EasyLogger::$logger->log($message);
}
public static function qLog($message){
EasyLogger::instantiate();
EasyLogger::$logger->log($message);
}
public static function quickLogCaller(){
EasyLogger::instantiate();
$bt = debug_backtrace();
$bt = array_shift($bt);
$caller = array_shift($bt);
EasyLogger::$logger->log(print_r($caller, true));
}
public function logThisVariable($var){
$this->log(var_export($var, true));
}
public function serializeThisVariable($var){
$this->log(serialize($var));
}
public function log($message){
if(is_string($message)) {
$date = new DateTime('now');
$txt = $date->format('d-m-Y H:i:s') . ' ' . $message . "\n";
fwrite($this->file, $txt);
}
else
$this->log(var_export($message, true));
return;
}
public function __destruct(){
fclose($this->file);
}
}
function ecLog($message){
EasyLogger::quickLog($message);
}