1
+ <?php
2
+ /**
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2018 Dogan Ucar, <dogan@dogan-ucar.de>
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ namespace doganoo \PHPUtil \Log ;
27
+
28
+ /**
29
+ * Class HTMLLogger
30
+ *
31
+ * TODO add other log levels
32
+ *
33
+ * @package doganoo\PHPUtil\Log
34
+ */
35
+ class HTMLLogger extends Logger {
36
+ private static $ path = null ;
37
+
38
+ /**
39
+ * Logger constructor prevents class instantiation
40
+ */
41
+ private function __construct () {
42
+ }
43
+
44
+ /**
45
+ * logs a message with log level INFO
46
+ *
47
+ * @param $message
48
+ */
49
+ public static function info ($ message ) {
50
+ parent ::setConfig (HTMLLogger::getConfiguration ());
51
+ parent ::info ($ message );
52
+ }
53
+
54
+ private static function getConfiguration (): array {
55
+ return array (
56
+ 'appenders ' => array (
57
+ 'default ' => array (
58
+ 'class ' => 'LoggerAppenderEcho ' ,
59
+ 'layout ' => array (
60
+ 'class ' => 'LoggerLayoutHtml ' ,
61
+ )
62
+ )
63
+ ),
64
+ 'rootLogger ' => array (
65
+ 'appenders ' => array ('default ' )
66
+ ),
67
+ );
68
+ }
69
+
70
+ /**
71
+ * returns the log path
72
+ *
73
+ * @return string
74
+ */
75
+ public static function getPath (): string {
76
+ return self ::$ path ;
77
+ }
78
+
79
+ /**
80
+ * sets the log path
81
+ *
82
+ * @param string $path
83
+ */
84
+ public static function setPath (string $ path ) {
85
+ self ::$ path = $ path ;
86
+ }
87
+
88
+ /**
89
+ * logs a message with log level WARN
90
+ *
91
+ * @param $message
92
+ */
93
+ public static function warn ($ message ) {
94
+ parent ::setConfig (HTMLLogger::getConfiguration ());
95
+ parent ::warn ($ message );
96
+ }
97
+
98
+ /**
99
+ * logs a message with log level ERROR
100
+ *
101
+ * @param $message
102
+ */
103
+ public static function error ($ message ) {
104
+ parent ::setConfig (HTMLLogger::getConfiguration ());
105
+ parent ::error ($ message );
106
+ }
107
+
108
+ /**
109
+ * logs a message with log level FATAL
110
+ *
111
+ * @param $message
112
+ */
113
+ public static function fatal ($ message ) {
114
+ parent ::setConfig (HTMLLogger::getConfiguration ());
115
+ parent ::fatal ($ message );
116
+ }
117
+
118
+ /**
119
+ * logs a message with log level TRACE
120
+ *
121
+ * @param $message
122
+ */
123
+ public static function trace ($ message ) {
124
+ parent ::setConfig (HTMLLogger::getConfiguration ());
125
+ parent ::trace ($ message );
126
+ }
127
+
128
+ /**
129
+ * logs a message with log level DEBUG
130
+ *
131
+ * @param $message
132
+ */
133
+ public static function debug ($ message ) {
134
+ parent ::setConfig (HTMLLogger::getConfiguration ());
135
+ parent ::debug ($ message );
136
+ }
137
+
138
+
139
+ }
0 commit comments