source: branches/old/administrace/process_log.php

Last change on this file was 410, checked in by george, 16 years ago
  • Opraveno: Povolování registrací. * Upraveno: Přehozeno pořadí vkládání logů mangosu do databáze. Největší naposled, nemusí se provést díky velikosti a chybě.
File size: 2.5 KB
Line 
1<?php
2
3include('global.php');
4
5$Content = file_get_contents($StdOutLogFile);
6$Lines = explode("\n", $Content);
7$Content = ''; // Free unused memory
8
9// Separate information from log file
10$Line = 0;
11while(($Line < count($Lines)) and (substr($Lines[$Line], 0, 6) != 'MaNGOS')) $Line++;
12$MangosVersion = $Lines[$Line];
13
14// Try to find start of backtrace
15while(($Line < count($Lines)) and (substr($Lines[$Line], 0, 16) != 'Program received')) $Line++;
16$Backtrace = array_slice($Lines, $Line, count($Lines) - $Line); // Assume rest of file to be backtrace
17$Backtrace = addslashes(implode("\n", $Backtrace));
18$Lines = '';
19
20//$Log = array_slice($Lines, 0, $Line);
21//$Log = addslashes(implode("\n", $Log));
22
23// Get used database version from database
24$DbResult = $Database->query('SELECT * FROM `'.$Config['Mangos']['DatabaseMangos'].'`.`db_version`');
25$DbRow = $DbResult->fetch_array();
26$DbVersion = $DbRow['version'];
27
28// Get last uptime info
29$DbResult = $Database->query('SELECT * FROM `'.$Config['Mangos']['DatabaseMangos'].'`.`uptime` ORDER BY `starttime` DESC LIMIT 1');
30echo($Database->error);
31$DbRow = $DbResult->fetch_array();
32$MaxPlayerCount = $DbRow['maxplayers'];
33$Uptime = $DbRow['uptime'];
34
35// Insert data to database
36$Database->query('INSERT INTO `debug` (`Time`, `MangosVersion`, `DbVersion`, `Uptime`, `MaxPlayerCount`) VALUES (NOW(), "'.
37 $MangosVersion.'", "'.$DbVersion.'", '.$Uptime.', '.$MaxPlayerCount.')');
38$InsertId = $Database->insert_id;
39
40// Insert data in separate query to partly avoid too long query packet error
41$Database->query('UPDATE `debug` SET Backtrace="'.$Backtrace.'" WHERE Id='.$InsertId);
42$Backtrace = '';
43//echo($Database->error);
44$Log = addslashes(file_get_contents($MangosLogFile));
45$Database->query('UPDATE `debug` SET Log="'.$Log.'" WHERE Id='.$InsertId);
46//echo($Database->error);
47$Log = addslashes(file_get_contents($MangosDbErrorsLogFile));
48$Database->query('UPDATE `debug` SET DbErrors="'.$Log.'" WHERE Id='.$InsertId);
49//echo($Database->error);
50
51$Configuration = array();
52$Log = addslashes(file_get_contents($MangosConfFile));
53$LogLines = explode("\n", $Log);
54foreach($LogLines as $LogLine)
55{
56 if(substr($LogLine, 0, 1) != '#') $Configuration[] = $LogLine;
57}
58$Database->query('UPDATE `debug` SET Configuration="'.implode("\n", $Configuration).'" WHERE Id='.$InsertId);
59
60//echo($Database->error);
61$Log = addslashes(file_get_contents($ErrOutLogFile));
62$Database->query('UPDATE `debug` SET ErrorLog="'.$Log.'" WHERE Id='.$InsertId);
63
64// Clear log files
65unlink($MangosLogFile);
66unlink($StdOutLogFile);
67unlink($ErrOutLogFile);
68unlink($MangosDbErrorsLogFile);
69
70?>
Note: See TracBrowser for help on using the repository browser.