forked from atis/raid-pokemon-bot
/
debug.php
42 lines (31 loc) · 799 Bytes
/
debug.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
<?php
function my_insert_id() {
global $db;
return $db->insert_id;
}
function my_query($query) {
global $db;
debug_log($query, '?');
$res = $db->query($query);
if ($db->error) {
debug_log($db->error,'!');
}
return $res;
}
function debug_log($val, $type = '*') {
$date = @date('Y-m-d H:i:s');
$usec = microtime(true);
$date = $date.'.'.str_pad(substr($usec,11,4),4,'0',STR_PAD_RIGHT);
$bt = debug_backtrace();
$bl = '';
while($btl=array_shift($bt)) {
if ($btl['function']==__FUNCTION__) continue;
$bl = '['.basename($btl['file']).':'.$btl['line'].'] ';
break;
}
if (gettype($val)!='string') $val = var_export($val,1);
$rows = explode("\n", $val);
foreach ($rows as $v) {
error_log('['.$date.']['.getmypid().'] '.$bl.$type.' '.$v."\n",3,CONFIG_LOGFILE);
}
}