Elgg
Version 1.9
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
engine
classes
Elgg
Logger.php
Go to the documentation of this file.
1
<?php
2
14
class
Elgg_Logger
{
15
16
const
OFF
= 0;
17
const
ERROR
= 400;
18
const
WARNING
= 300;
19
const
NOTICE
= 250;
20
const
INFO
= 200;
21
22
protected
static
$levels
= array(
23
0 =>
'OFF'
,
24
200 =>
'INFO'
,
25
250 =>
'NOTICE'
,
26
300 =>
'WARNING'
,
27
400 =>
'ERROR'
,
28
);
29
31
protected
$level
=
self::ERROR
;
32
34
protected
$display
=
false
;
35
37
protected
$hooks
;
38
44
public
function
__construct
(
Elgg_PluginHooksService
$hooks
) {
45
$this->hooks =
$hooks
;
46
}
47
54
public
function
setLevel
(
$level
) {
55
// @todo Elgg has used string constants for logging levels
56
if
(is_string(
$level
)) {
57
$levelStringsToInts = array_flip(self::$levels);
58
$level
= $levelStringsToInts[
$level
];
59
}
60
$this->level =
$level
;
61
}
62
68
public
function
getLevel
() {
69
return
$this->level
;
70
}
71
82
public
function
setDisplay
(
$display
) {
83
$this->display =
$display
;
84
}
85
93
public
function
log
(
$message
,
$level
= self::NOTICE) {
94
if
($this->level == self::OFF || $level < $this->level) {
95
return
false
;
96
}
97
98
if
(!array_key_exists(
$level
, self::$levels)) {
99
return
false
;
100
}
101
102
$levelString = self::$levels[
$level
];
103
104
// notices and below never displayed to user
105
$display
= $this->display &&
$level
> self::NOTICE;
106
107
$this->
process
(
"$levelString: $message"
,
$display
,
$level
);
108
109
return
true
;
110
}
111
118
public
function
error
(
$message
) {
119
return
$this->
log
(
$message
,
self::ERROR
);
120
}
121
128
public
function
warn
(
$message
) {
129
return
$this->
log
(
$message
, self::WARNING);
130
}
131
138
public
function
notice
(
$message
) {
139
return
$this->
log
(
$message
, self::NOTICE);
140
}
141
148
public
function
info
(
$message
) {
149
return
$this->
log
(
$message
, self::INFO);
150
}
151
159
public
function
dump
(
$data
,
$display
=
true
) {
160
$this->
process
(
$data
,
$display
,
self::ERROR
);
161
}
162
171
protected
function
process
(
$data
,
$display
,
$level
) {
172
global
$CONFIG
;
173
174
// plugin can return false to stop the default logging method
175
$params
= array(
176
'level'
=>
$level
,
177
'msg'
=>
$data
,
178
'display'
=>
$display
,
179
'to_screen'
=>
$display
,
180
);
181
182
if
(!$this->hooks->trigger(
'debug'
,
'log'
,
$params
,
true
)) {
183
return
;
184
}
185
186
// Do not want to write to screen before page creation has started.
187
// This is not fool-proof but probably fixes 95% of the cases when logging
188
// results in data sent to the browser before the page is begun.
189
if
(!isset($CONFIG->pagesetupdone)) {
190
$display
=
false
;
191
}
192
193
// Do not want to write to JS or CSS pages
194
if
(
elgg_in_context
(
'js'
) ||
elgg_in_context
(
'css'
)) {
195
$display
=
false
;
196
}
197
198
if
(
$display
==
true
) {
199
echo
'<pre class="elgg-logger-data">'
;
200
echo
htmlspecialchars(print_r(
$data
,
true
), ENT_QUOTES,
'UTF-8'
);
201
echo
'</pre>'
;
202
}
else
{
203
error_log(print_r(
$data
,
true
));
204
}
205
}
206
}
Elgg_Logger\ERROR
const ERROR
Definition:
Logger.php:17
Elgg_Logger\$level
$level
Definition:
Logger.php:31
Elgg_Logger\error
error($message)
Log message at the ERROR level.
Definition:
Logger.php:118
Elgg_Logger\process
process($data, $display, $level)
Process logging data.
Definition:
Logger.php:171
Elgg_Logger\log
log($message, $level=self::NOTICE)
Add a message to the log.
Definition:
Logger.php:93
Elgg_Logger\OFF
const OFF
Definition:
Logger.php:16
Elgg_Logger\$display
$display
Definition:
Logger.php:34
Elgg_Logger\notice
notice($message)
Log message at the NOTICE level.
Definition:
Logger.php:138
$message
$message
Definition:
set_maintenance_mode.php:7
$data
$data
Definition:
opendd.php:13
Elgg_Logger\$levels
static $levels
Definition:
Logger.php:22
Elgg_Logger\INFO
const INFO
Definition:
Logger.php:20
Elgg_Logger\dump
dump($data, $display=true)
Dump data to log or screen.
Definition:
Logger.php:159
$params
$params
Definition:
login.php:72
Elgg_Logger\info
info($message)
Log message at the INFO level.
Definition:
Logger.php:148
Elgg_Logger\warn
warn($message)
Log message at the WARNING level.
Definition:
Logger.php:128
Elgg_Logger
Definition:
Logger.php:14
Elgg_Logger\getLevel
getLevel()
Get the current logging level.
Definition:
Logger.php:68
Elgg_Logger\setDisplay
setDisplay($display)
Set whether the logging should be displayed to the user.
Definition:
Logger.php:82
$CONFIG
global $CONFIG
Definition:
settings.example.php:17
elgg_in_context
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition:
pageowner.php:273
echo
elgg echo
Translates a string.
Definition:
languages.js:43
global
elgg global
Pointer to the global context.
Definition:
elgglib.js:12
Elgg_PluginHooksService
Definition:
PluginHooksService.php:14
Elgg_Logger\$hooks
$hooks
Definition:
Logger.php:37
ERROR
elgg ajax ERROR
Definition:
ajax.js:33
Elgg_Logger\setLevel
setLevel($level)
Set the logging level.
Definition:
Logger.php:54
Elgg_Logger\__construct
__construct(Elgg_PluginHooksService $hooks)
Constructor.
Definition:
Logger.php:44
Elgg_Logger\NOTICE
const NOTICE
Definition:
Logger.php:19
Elgg_Logger\WARNING
const WARNING
Definition:
Logger.php:18
Generated on Sat Dec 21 2024 00:00:35 for Elgg by
1.8.11