forked from k0a1a/hotglue2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.inc.php
67 lines (58 loc) · 1.43 KB
/
log.inc.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
<?php
/*
* log.inc.php
* Generic logging infrastructure
*
* Copyright Gottfried Haider, Danja Vasiliev 2010.
* This source code is licensed under the GNU General Public License.
* See the file COPYING for more details.
*/
@require_once('config.inc.php');
require_once('util.inc.php');
if (!isset($logfile)) {
$logfile = false;
}
if (!isset($loglevels)) {
$loglevels = array('error', 'warn', 'info', 'debug');
}
if (!isset($request_id)) {
// mt_rand() is seeded automatically
$request_id = mt_rand(1, 32768);
}
/**
* log a message to file
*
* @param string $level can be error, warn, info or debug
* @param string $msg message
* @return bool true if successful, false if not
*/
function log_msg($level, $msg )
{
global $logfile;
global $loglevels;
global $request_id;
// open logfile
if ($logfile === false) {
$m = umask(0111);
// having two processes appending to the same file should
// work fine (at least on Linux)
$logfile = @fopen(LOG_FILE, 'ab');
umask($m);
}
if ($logfile === false) {
return false;
}
foreach ($loglevels as $ll) {
if ($ll == $level) {
fwrite($logfile, date('Y-m-d H:i:s').tab().pad($_SERVER['REMOTE_ADDR'], 15).tab().sprintf('%05u', $request_id).tab().$level.tab().$msg.nl());
fflush($logfile);
break;
}
if ($ll == LOG_LEVEL) {
break;
}
}
return true;
}
// we need no extra function to log response-arrays as they are logged further
// down in the server (e.g. json.php)