ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLoggingErrorFileStorage.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2016 Stefan Hecken, Extended GPL, see docs/LICENSE */
3require_once './libs/composer/vendor/autoload.php';
4
6
13 const KEY_SPACE = 25;
14 const FILE_FORMAT = ".log";
15
16 public function __construct($inspector, $file_path, $file_name) {
17 $this->inspector = $inspector;
18 $this->file_path = $file_path;
19 $this->file_name = $file_name;
20 }
21
22 protected function createDir($path) {
23 if(!is_dir($this->file_path)) {
24 ilUtil::makeDirParents($this->file_path);
25 }
26 }
27
28 protected function content() {
29 return $this->pageHeader()
30 .$this->exceptionContent()
31 .$this->tablesContent()
32 ;
33 }
34
35 public function write() {
36 $this->createDir($this->file_path);
37
38 $file_name = $this->file_path."/".$this->file_name.self::FILE_FORMAT;
39 $stream = fopen($file_name, 'w+');
40 fwrite($stream, $this->content());
41 fclose($stream);
42 chmod($file_name, 0755);
43 }
44
50 protected function pageHeader() {
51 return "";
52 }
53
59 protected function exceptionContent() {
60 return Formatter::formatExceptionPlain($this->inspector);
61 }
62
68 protected function tablesContent() {
69 $ret = "";
70 foreach ($this->tables() as $title => $content) {
71 $ret .= "\n\n-- $title --\n\n";
72 if (count($content) > 0) {
73 foreach ($content as $key => $value) {
74 $key = str_pad($key, self::KEY_SPACE);
75
76 // indent multiline values, first print_r, split in lines,
77 // indent all but first line, then implode again.
78 $first = true;
79 $indentation = str_pad("", self::KEY_SPACE);
80 $value = implode("\n", array_map(function($line) use (&$first, $indentation) {
81 if ($first) {
82 $first = false;
83 return $line;
84 }
85 return $indentation.$line;
86 }, explode("\n", print_r($value, true))));
87
88 $ret .= "$key: $value\n";
89 }
90 }
91 else {
92 $ret .= "empty\n";
93 }
94 }
95 return $ret;
96 }
97
103 protected function tables() {
104 $post = $_POST;
106
107 $post = $this->hidePassword($post);
109
110 return array
111 ( "GET Data" => $_GET
112 , "POST Data" => $post
113 , "Files" => $_FILES
114 , "Cookies" => $_COOKIE
115 , "Session" => isset($_SESSION) ? $_SESSION : array()
116 , "Server/Request Data" => $server
117 , "Environment Variables" => $_ENV
118 );
119 }
120
128 private function hidePassword(array $post) {
129 if(isset($post["password"])) {
130 $post["password"] = "REMOVED FOR SECURITY";
131 }
132
133 return $post;
134 }
135
143 private function shortenPHPSessionId(array $server) {
144 global $ilLog;
145
146 $cookie_content = $server["HTTP_COOKIE"];
147 $cookie_content = explode(";", $cookie_content);
148
149 foreach ($cookie_content as $key => $content) {
150 $content_array = explode("=", $content);
151 if(trim($content_array[0]) == session_name()) {
152 $content_array[1] = substr($content_array[1], 0, 5)." (SHORTENED FOR SECURITY)";
153 $cookie_content[$key] = implode("=", $content_array);
154 }
155 }
156
157 $server["HTTP_COOKIE"] = implode(";", $cookie_content);
158
159 return $server;
160 }
161}
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
$path
Definition: aliased.php:25
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Saves error informations into file.
hidePassword(array $post)
Replace passwort from post array with security message.
__construct($inspector, $file_path, $file_name)
pageHeader()
Get the header for the page.
exceptionContent()
Get a short info about the exception.
tablesContent()
Get the header for the page.
tables()
Get the tables that should be rendered.
shortenPHPSessionId(array $server)
Shorts the php session id.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$server
$ret
Definition: parser.php:6
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']