Logfile.php 6.8 KB

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