|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2018 Justin Kuenzel (jukusoft.com) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Project: RocketCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 21.08.2018 |
|
25
|
|
|
* Time: 19:33 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
class Logger { |
|
29
|
|
|
|
|
30
|
|
|
//instance of logging provider |
|
31
|
|
|
protected static $provider = null; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* initialize logging provider |
|
35
|
|
|
*/ |
|
36
|
|
|
public static function init () { |
|
37
|
|
|
self::getProvider()->init(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* log message |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function log (string $level, string $message, $args = array()) { |
|
44
|
|
|
self::getProvider()->log($level, $message, $args); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* lazy logging - write logs into file or send it to server |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function send () { |
|
51
|
|
|
self::getProvider()->send(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public static function &getProvider () : LogProvider { |
|
55
|
|
|
if (self::$provider == null) { |
|
56
|
|
|
if (defined("LOGGING_ENABLED") && LOGGING_ENABLED == true) { |
|
|
|
|
|
|
57
|
|
|
//search for loggging provider |
|
58
|
|
|
$logging_provider = Settings::get("logging_provider", "EmptyLogProvider"); |
|
59
|
|
|
|
|
60
|
|
|
//create new instance of class in string |
|
61
|
|
|
self::$provider = new $logging_provider(); |
|
62
|
|
|
} else { |
|
63
|
|
|
//use dummy logging provider, which doesnt do anything |
|
64
|
|
|
self::$provider = new EmptyLogProvider(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return self::$provider; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
?> |
|
|
|
|
|
|
74
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.