-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoreLog.php
104 lines (88 loc) · 2.26 KB
/
CoreLog.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
require_once(dirname(dirname(__FILE__)).'/Config.php');
require_once('CoreDebug.php');
class CoreLog {
/**
* Toggle logging of normal events.
*
* @var boolean
*/
private static $enabled = true;
/**
* Toggle debugging- these are events that shouldn't happen.
* If they do they indicate a need to debug the problem.
* They are thrown in production.
*
* @var boolean
*/
private static $debugEnabled = true;
/**
* General log
*
* @param string $msg
* @param string $logName
* @return
*/
public static function add($msg, $logName = 'core_events') {
if (self::$enabled == false) {
return;
}
self::createLog($msg, $logName);
}
/**
* Events that should never happen and may indicate an error.
*
* @param string $msg
* @param string $logName
* @return
*/
public static function debug($msg, $logName = 'debug_log') {
if (self::$debugEnabled == false) {
return;
}
self::createLog($msg, $logName);
}
/**
* Automated tasks output log.
*
* @param string $msg
* @param string $logName
* @return
*/
public static function cron($msg, $logName = 'cron_log') {
self::createLog($msg, $logName);
}
/**
* Creates a trace of an error in the trace log.
* Used for testing and debugging.
*
* @return
*/
public static function trace(){
self::createLog(CoreDebug::backtrace(debug_backtrace()) , 'trace_log');
}
/**
* Authorization protocol logging
*
* @param string $msg
* @param string $logName
* @return
*/
public static function auth($msg, $logName = 'authorization_log') {
self::createLog($msg, $logName);
}
/**
* Creates a log entry in the specified log.
*
* @param string $msg
* @param string $logName
* @return
*/
private static function createLog($msg, $logName = 'debug_log') {
$file = Config::$LOG_PATH . $logName . ' ' . date('Y-m-d') . '.log';
$logMsg = date('Y-m-d H:i:s') . "; ";
$logMsg .= $msg . "\n";
file_put_contents($file, $logMsg, FILE_APPEND);
}
}
?>