00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 @require_once('config.inc.php');
00013 require_once('util.inc.php');
00014
00015 if (!isset($logfile)) {
00016 $logfile = false;
00017 }
00018 if (!isset($loglevels)) {
00019 $loglevels = array('error', 'warn', 'info', 'debug');
00020 }
00021 if (!isset($request_id)) {
00022
00023 $request_id = mt_rand(1, 32768);
00024 }
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 function log_msg($level, $msg )
00035 {
00036 global $logfile;
00037 global $loglevels;
00038 global $request_id;
00039
00040
00041 if ($logfile === false) {
00042 $m = umask(0111);
00043
00044
00045 $logfile = @fopen(LOG_FILE, 'ab');
00046 umask($m);
00047 }
00048 if ($logfile === false) {
00049 return false;
00050 }
00051
00052 foreach ($loglevels as $ll) {
00053 if ($ll == $level) {
00054 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());
00055 fflush($logfile);
00056 break;
00057 }
00058 if ($ll == LOG_LEVEL) {
00059 break;
00060 }
00061 }
00062 return true;
00063 }
00064
00065
00066
00067