forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxLog.php
More file actions
224 lines (203 loc) · 3.22 KB
/
mxLog.php
File metadata and controls
224 lines (203 loc) · 3.22 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
/**
* $Id: mxLog.php,v 1.1 2012/11/15 13:26:48 gaudenz Exp $
* Copyright (c) 2006-2010, Gaudenz Alder
*/
class mxLog
{
/**
* Class: mxLog
*
* Logging facility.
*
* Variable: level_fine
*
* Specifies the fine logging level.
*/
public static $level_fine = true;
/**
* Variable: level_debug
*
* Specifies the debug logging level.
*/
public static $level_debug = true;
/**
* Variable: level_info
*
* Specifies the info logging level.
*/
public static $level_info = true;
/**
* Variable: level_warn
*
* Specifies the warn logging level.
*/
public static $level_warn = true;
/**
* Variable: level_error
*
* Specifies the error logging level.
*/
public static $level_error = true;
/**
* Variable: current
*
* Default is true.
*/
public static $current = array();
/**
* Variable: tab
*
* Default is true.
*/
public static $tab = "";
/**
* Variable: logfiles
*
* Holds the array of logfiles.
*/
public static $logfiles = array();
/**
* Variable: printLog
*
* Specifies if the log should be printed out.
*/
public static $printLog = false;
/**
* Function: addLogfile
*
* Adds a file for logging.
*/
static function addLogfile($filename)
{
$fh = fopen($filename, "a");
array_push(mxLog::$logfiles, $fh);
}
/**
* Function: enter
*
* Logs a method entry.
*/
static function enter($method, $text="")
{
mxLog::writeln("$method: { $text");
$t0 = microtime(true);
array_push(mxLog::$current, $t0);
mxLog::$tab .= " ";
}
/**
* Function: leave
*
* Logs a method exit.
*/
static function leave($text="")
{
$t0 = array_pop(mxLog::$current);
$tab = mxLog::$tab;
mxLog::$tab = substr($tab, 0, strlen($tab)-4);
$dt = "(dt=".(microtime(true)-$t0).")";
mxLog::writeln("} $dt $text");
}
/**
* Function: fine
*
* Logs a fine trace.
*/
static function fine($text)
{
if (mxLog::$level_fine)
{
mxLog::writeln($text);
}
}
/**
* Function: debug
*
* Logs a debug trace.
*/
static function debug($text)
{
if (mxLog::$level_debug)
{
mxLog::writeln($text);
}
}
/**
* Function: info
*
* Logs an info trace.
*/
static function info($text)
{
if (mxLog::$level_info)
{
mxLog::writeln($text);
}
}
/**
* Function: warn
*
* Logs a warn trace.
*/
static function warn($text)
{
if (mxLog::$level_warn)
{
mxLog::writeln($text);
error_log($text);
}
}
/**
* Function: error
*
* Logs an error trace.
*/
static function error($text)
{
if (mxLog::$level_error)
{
mxLog::writeln($text);
error_log($text);
}
}
/**
* Function: writeln
*
* Writes a line with a linefeed to the log.
*/
static function writeln($text)
{
mxLog::write("$text\n");
}
/**
* Function: write
*
* Writes a line to the log.
*/
static function write($text)
{
$msg = date("Y-m-d H:i:s").": ".mxLog::$tab.$text;
foreach (mxLog::$logfiles as $fh)
{
fputs($fh, $msg);
}
if (mxLog::$printLog)
{
$msg = str_replace(" ", " ", $msg);
print("$msg<br>");
}
}
/**
* Function: close
*
* Closes all open logfiles.
*/
static function close()
{
foreach (mxLog::$logfiles as $fh)
{
fclose($fh);
}
}
}
?>