Logfile.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. class Logfile
  3. {
  4. public $Name;
  5. public $Type = "Modell";
  6. public $Filename;
  7. public $Modified;
  8. public $LastChangedDays;
  9. public $Errors = array();
  10. public $ErrorLevel = 5;
  11. public $Sources = array();
  12. public $Summary;
  13. function __construct($filename)
  14. {
  15. $this->Filename = $filename;
  16. $pathinfo = pathinfo($filename);
  17. $this->Name = $pathinfo['filename'];
  18. $this->Modified = str_replace(" ", "T", date("Y-m-d H:i:s", filemtime($filename)));
  19. $this->LastChangedDays = $this->dateDiff($this->Modified, date("Y-m-d H:i:s"));
  20. if (preg_match("/\.xml/", $this->Filename)) {
  21. $this->Type = (stripos($this->Filename, "ver") == false) ? "Portal" : "Versand";
  22. $errors = json_decode(implode("",file($this->Filename)));
  23. if (isset($errors->errors)) {
  24. if (count($errors->errors) > 0) {
  25. $this->ErrorLevel = 2;
  26. }
  27. $this->Errors = $errors->errors;
  28. $this->Sources = $errors->sources;
  29. $this->Summary = $errors->summary;
  30. }
  31. } else if (preg_match("/\.\D+\.log$/", $this->Filename)) {
  32. $this->Type = "Workflow";
  33. $this->Errors = array(implode("\r\n", $this->Content()));
  34. $this->ErrorLevel = 3;
  35. } else {
  36. $this->transformerErrors();
  37. $this->benchmark();
  38. if ($this->ErrorLevel <= 2 && $this->Summary) {
  39. $this->ErrorLevel = 3;
  40. }
  41. if (!$this->Summary) {
  42. $this->ErrorLevel = 2;
  43. }
  44. }
  45. }
  46. function Content()
  47. {
  48. $content = file_get_contents($this->Filename);
  49. $content = mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, "UTF-8, ISO-8859-1, Windows-1252, CP850", true));
  50. return explode("\r\n", $content);
  51. }
  52. function Link() {
  53. $link = $this->Name;
  54. if (preg_match("/(.*)\.\d+$/", $link, $match)) {
  55. $link = $match[1];
  56. }
  57. return "<a href=\"http://wiki.global-cube.de/{$link}\">{$this->Name}</a>";
  58. }
  59. private function webCreatorErrors()
  60. {
  61. foreach ($this->Content() as $line) {
  62. if (preg_match("/^\w+/", $line) && !preg_match("/^(com|Source)/", $line)) {
  63. $e = new WebCreatorError($line);
  64. if ($e->Level < $this->ErrorLevel)
  65. $this->ErrorLevel = $e->Level;
  66. $this->Errors[] = $e;
  67. }
  68. }
  69. }
  70. private function copyAndReplaceErrors()
  71. {
  72. foreach ($this->Content() as $line) {
  73. $e = new CopyAndReplaceError($line);
  74. if ($e->Level < $this->ErrorLevel)
  75. $this->ErrorLevel = $e->Level;
  76. $this->Errors[] = $e;
  77. }
  78. }
  79. private function transformerErrors()
  80. {
  81. foreach ($this->Content() as $line) {
  82. if (preg_match("/\(TR\d*\)|DMS-E-GENERAL/", $line)) {
  83. $e = new TransformerError($line);
  84. if ($e->Level < $this->ErrorLevel)
  85. $this->ErrorLevel = $e->Level;
  86. $this->Errors[] = $e;
  87. }
  88. }
  89. }
  90. private function benchmark()
  91. {
  92. $current = null;
  93. foreach ($this->Content() as $line) {
  94. if (preg_match("/Verarbeitung von (\d*) Datens.+tzen der Datenquelle `(.*)` wird beendet/", $line, $match)) {
  95. $current = new Source($match[2], $match[1]);
  96. } else if ($current && preg_match("/DATENQUELLE GELESEN,\s*([\d:]+)/", $line, $match)) {
  97. $current->Duration = $match[1];
  98. $this->Sources[] = $current;
  99. $current = null;
  100. } else if (preg_match("/Durchgang \d+ wird ausgef.+hrt\. Es verbleiben (\d*) Zeilen und (\d*) Kategorien/", $line, $match)) {
  101. $this->Summary = new Summary($match[1], $match[2]);
  102. } else if ($this->Summary && preg_match("/ZEIT INSGESAMT \(CUBE ERSTELLEN\),\s*([\d:]+)/", $line, $match)) {
  103. $this->Summary->Duration = $match[1];
  104. }
  105. }
  106. }
  107. private function dateDiff($d1, $d2)
  108. {
  109. $diff = round((strtotime($d2) - strtotime($d1)) / (24 * 60 * 60));
  110. return $diff;
  111. }
  112. private function formatMessage($message)
  113. {
  114. $message = str_replace("'", "`", $message);
  115. $message = str_replace("\"", "`", $message);
  116. $message = str_replace("ä", "ae", $message);
  117. $message = str_replace("ö", "oe", $message);
  118. $message = str_replace("ü", "ue", $message);
  119. $message = str_replace("ß", "ss", $message);
  120. $message = str_replace("Ä", "Ae", $message);
  121. $message = str_replace("Ö", "Oe", $message);
  122. $message = str_replace("Ü", "Ue", $message);
  123. $message = str_replace("[->OK]", "", $message);
  124. $message = str_replace("\r", "", $message);
  125. $message = str_replace("\n", "", $message);
  126. return $message;
  127. }
  128. }
  129. class TransformerError
  130. {
  131. public $Number;
  132. public $Message;
  133. public $Timestamp;
  134. public $Level;
  135. function __construct($line = 0)
  136. {
  137. if ($line) {
  138. $cols = explode("\t", $line);
  139. $this->Timestamp = $this->formatLogDate($cols[0]);
  140. $this->Level = $cols[1];
  141. if (preg_match("/\((TR\d*)\) (.*)/", $cols[3], $match)) {
  142. $this->Number = $match[1];
  143. if ($this->Number == "TR0220") {
  144. $this->Level = 1;
  145. }
  146. $this->Message = $match[2];
  147. } if (preg_match("/DMS-E-GENERAL (.*)/", $cols[3], $match)) {
  148. $this->Number = "TR0109";
  149. $this->Message = $cols[3];
  150. $this->Level = 1;
  151. }
  152. }
  153. }
  154. private function formatLogDate($message)
  155. {
  156. $message = substr($message, 3);
  157. $message = str_replace(" Jan ", ".01.", $message);
  158. $message = str_replace(" Feb ", ".02.", $message);
  159. $message = str_replace(" Mrz ", ".03.", $message);
  160. $message = str_replace(" Apr ", ".04.", $message);
  161. $message = str_replace(" Mai ", ".05.", $message);
  162. $message = str_replace(" Jun ", ".06.", $message);
  163. $message = str_replace(" Jul ", ".07.", $message);
  164. $message = str_replace(" Aug ", ".08.", $message);
  165. $message = str_replace(" Sep ", ".09.", $message);
  166. $message = str_replace(" Okt ", ".10.", $message);
  167. $message = str_replace(" Nov ", ".11.", $message);
  168. $message = str_replace(" Dez ", ".12.", $message);
  169. if (preg_match("/(\d{2}).(\d{2}).(\d{4})\s*([\d:]+)/", $message, $match)) {
  170. return "{$match[3]}-{$match[2]}-{$match[1]}T{$match[4]}";
  171. }
  172. return "";
  173. }
  174. }
  175. class WebCreatorError
  176. {
  177. public $Number = "WC0000";
  178. public $Message;
  179. public $Timestamp;
  180. public $Level = 2;
  181. function __construct($line = 0)
  182. {
  183. if ($line) {
  184. if (preg_match("/^Description: (.*)/", $line, $match)) {
  185. $this->Message = $match[1];
  186. if (preg_match("/Division durch Null/", $this->Message)) {
  187. $this->Level = 4;
  188. $this->Number = "WC0001";
  189. }
  190. if (preg_match("/Kategorieindex/", $this->Message)) {
  191. $this->Level = 4;
  192. $this->Number = "WC0002";
  193. }
  194. } else {
  195. $this->Message = $line;
  196. }
  197. }
  198. }
  199. }
  200. class CopyAndReplaceError
  201. {
  202. public $Number = "CR0000";
  203. public $Message;
  204. public $Timestamp;
  205. public $Level = 3;
  206. function __construct($line = 0)
  207. {
  208. $this->Message = $line;
  209. }
  210. }
  211. class WorkflowError
  212. {
  213. public $Filename;
  214. public $User;
  215. public $Report;
  216. public $ReportModified;
  217. public $Layer;
  218. public $MailTo;
  219. public $Modified;
  220. public function __toString() {
  221. return $this->Report . ".ppr, " . $this->Layer . ": " . substr($this->Filename, -3) . " " . $this->Modified;
  222. }
  223. }
  224. class Source
  225. {
  226. public $Filename;
  227. public $Report;
  228. public $Layer;
  229. public $Entities;
  230. public $Duration;
  231. function __construct($filename, $entities = 0)
  232. {
  233. $this->Filename = $filename;
  234. $this->Entities = $entities;
  235. }
  236. }
  237. class Summary
  238. {
  239. public $Entities;
  240. public $Categories;
  241. public $Duration;
  242. function __construct($entities, $categories = 0)
  243. {
  244. $this->Entities = $entities;
  245. $this->Categories = $categories;
  246. }
  247. }
  248. ?>