ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Monolog\Handler\ChromePHPHandler Class Reference

Handler sending logs to the ChromePHP extension (http://www.chromephp.com/) More...

+ Inheritance diagram for Monolog\Handler\ChromePHPHandler:
+ Collaboration diagram for Monolog\Handler\ChromePHPHandler:

Public Member Functions

 __construct ($level=Logger::DEBUG, $bubble=true)
 
 handleBatch (array $records)
 {{Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
}} More...
 
 __get ($property)
 BC getter for the sendHeaders property that has been made static. More...
 
 __set ($property, $value)
 BC setter for the sendHeaders property that has been made static. More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
Boolean
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 
 isHandling (array $record)
 Checks whether the given record will be handled by this handler. More...
 
 handle (array $record)
 Handles a record. More...
 
 handleBatch (array $records)
 Handles a set of records at once. More...
 
 pushProcessor ($callback)
 Adds a processor in the stack. More...
 
 popProcessor ()
 Removes the processor on top of the stack and returns it. More...
 
 setFormatter (FormatterInterface $formatter)
 Sets the formatter. More...
 
 getFormatter ()
 Gets the formatter. More...
 

Data Fields

const VERSION = '4.0'
 Version of the extension. More...
 
const HEADER_NAME = 'X-ChromeLogger-Data'
 Header name. More...
 
const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}'
 Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+) More...
 

Protected Member Functions

 getDefaultFormatter ()
 Gets the default formatter.
Returns
FormatterInterface
More...
 
 write (array $record)
 Creates & sends header for a record. More...
 
 send ()
 Sends the log header. More...
 
 sendHeader ($header, $content)
 Send header string to the client. More...
 
 headersAccepted ()
 Verifies if the headers are accepted by the current user agent. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Static Protected Attributes

static $initialized = false
 
static $overflowed = false
 
static $json
 
static $sendHeaders = true
 

Additional Inherited Members

- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Detailed Description

Handler sending logs to the ChromePHP extension (http://www.chromephp.com/)

This also works out of the box with Firefox 43+

Author
Christophe Coevoet stof@.nosp@m.notk.nosp@m..org

Definition at line 24 of file ChromePHPHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\ChromePHPHandler::__construct (   $level = Logger::DEBUG,
  $bubble = true 
)
Parameters
int$levelThe minimum logging level at which this handler will be triggered
Boolean$bubbleWhether the messages that are handled can bubble up the stack or not

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 64 of file ChromePHPHandler.php.

65 {
66 parent::__construct($level, $bubble);
67 if (!function_exists('json_encode')) {
68 throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s ChromePHPHandler');
69 }
70 }

References Monolog\Handler\AbstractHandler\$bubble, and Monolog\Handler\AbstractHandler\$level.

Member Function Documentation

◆ __get()

Monolog\Handler\ChromePHPHandler::__get (   $property)

BC getter for the sendHeaders property that has been made static.

Definition at line 191 of file ChromePHPHandler.php.

192 {
193 if ('sendHeaders' !== $property) {
194 throw new \InvalidArgumentException('Undefined property '.$property);
195 }
196
197 return static::$sendHeaders;
198 }

◆ __set()

Monolog\Handler\ChromePHPHandler::__set (   $property,
  $value 
)

BC setter for the sendHeaders property that has been made static.

Definition at line 203 of file ChromePHPHandler.php.

204 {
205 if ('sendHeaders' !== $property) {
206 throw new \InvalidArgumentException('Undefined property '.$property);
207 }
208
209 static::$sendHeaders = $value;
210 }

◆ getDefaultFormatter()

Monolog\Handler\ChromePHPHandler::getDefaultFormatter ( )
protected

Gets the default formatter.

Returns
FormatterInterface

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 96 of file ChromePHPHandler.php.

97 {
98 return new ChromePHPFormatter();
99 }

◆ handleBatch()

Monolog\Handler\ChromePHPHandler::handleBatch ( array  $records)

{{Handles a set of records at once.

Parameters
array$recordsThe records to handle (an array of record arrays)
}}

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 75 of file ChromePHPHandler.php.

76 {
77 $messages = array();
78
79 foreach ($records as $record) {
80 if ($record['level'] < $this->level) {
81 continue;
82 }
83 $messages[] = $this->processRecord($record);
84 }
85
86 if (!empty($messages)) {
87 $messages = $this->getFormatter()->formatBatch($messages);
88 self::$json['rows'] = array_merge(self::$json['rows'], $messages);
89 $this->send();
90 }
91 }
getFormatter()
{Gets the formatter.FormatterInterface}
processRecord(array $record)
Processes a record.
$messages
Definition: en-x-test.php:7
$records
Definition: simple_test.php:22

References $messages, $records, Monolog\Handler\AbstractHandler\getFormatter(), Monolog\Handler\AbstractProcessingHandler\processRecord(), and Monolog\Handler\ChromePHPHandler\send().

+ Here is the call graph for this function:

◆ headersAccepted()

Monolog\Handler\ChromePHPHandler::headersAccepted ( )
protected

Verifies if the headers are accepted by the current user agent.

Returns
Boolean

Definition at line 179 of file ChromePHPHandler.php.

180 {
181 if (empty($_SERVER['HTTP_USER_AGENT'])) {
182 return false;
183 }
184
185 return preg_match(self::USER_AGENT_REGEX, $_SERVER['HTTP_USER_AGENT']);
186 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

References $_SERVER.

Referenced by Monolog\Handler\ChromePHPHandler\send().

+ Here is the caller graph for this function:

◆ send()

Monolog\Handler\ChromePHPHandler::send ( )
protected

Sends the log header.

See also
sendHeader()

Definition at line 120 of file ChromePHPHandler.php.

121 {
122 if (self::$overflowed || !self::$sendHeaders) {
123 return;
124 }
125
126 if (!self::$initialized) {
127 self::$initialized = true;
128
129 self::$sendHeaders = $this->headersAccepted();
130 if (!self::$sendHeaders) {
131 return;
132 }
133
134 self::$json['request_uri'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
135 }
136
137 $json = @json_encode(self::$json);
138 $data = base64_encode(utf8_encode($json));
139 if (strlen($data) > 240 * 1024) {
140 self::$overflowed = true;
141
142 $record = array(
143 'message' => 'Incomplete logs, chrome header size limit reached',
144 'context' => array(),
145 'level' => Logger::WARNING,
146 'level_name' => Logger::getLevelName(Logger::WARNING),
147 'channel' => 'monolog',
148 'datetime' => new \DateTime(),
149 'extra' => array(),
150 );
151 self::$json['rows'][count(self::$json['rows']) - 1] = $this->getFormatter()->format($record);
152 $json = @json_encode(self::$json);
153 $data = base64_encode(utf8_encode($json));
154 }
155
156 if (trim($data) !== '') {
157 $this->sendHeader(self::HEADER_NAME, $data);
158 }
159 }
headersAccepted()
Verifies if the headers are accepted by the current user agent.
sendHeader($header, $content)
Send header string to the client.
static getLevelName($level)
Gets the name of the logging level.
Definition: Logger.php:458
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52

References $_SERVER, $data, Monolog\Handler\ChromePHPHandler\$json, Monolog\Handler\AbstractHandler\getFormatter(), Monolog\Logger\getLevelName(), Monolog\Handler\ChromePHPHandler\headersAccepted(), Monolog\Handler\ChromePHPHandler\sendHeader(), and Monolog\Logger\WARNING.

Referenced by Monolog\Handler\ChromePHPHandler\handleBatch(), and Monolog\Handler\ChromePHPHandler\write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendHeader()

Monolog\Handler\ChromePHPHandler::sendHeader (   $header,
  $content 
)
protected

Send header string to the client.

Parameters
string$header
string$content

Reimplemented in Monolog\Handler\TestChromePHPHandler.

Definition at line 167 of file ChromePHPHandler.php.

168 {
169 if (!headers_sent() && self::$sendHeaders) {
170 header(sprintf('%s: %s', $header, $content));
171 }
172 }
sprintf('%.4f', $callTime)

References $header, and sprintf.

Referenced by Monolog\Handler\ChromePHPHandler\send().

+ Here is the caller graph for this function:

◆ write()

Monolog\Handler\ChromePHPHandler::write ( array  $record)
protected

Creates & sends header for a record.

See also
sendHeader()
send()
Parameters
array$record

Reimplemented from Monolog\Handler\AbstractProcessingHandler.

Definition at line 108 of file ChromePHPHandler.php.

109 {
110 self::$json['rows'][] = $record['formatted'];
111
112 $this->send();
113 }

References Monolog\Handler\ChromePHPHandler\send().

+ Here is the call graph for this function:

Field Documentation

◆ $initialized

Monolog\Handler\ChromePHPHandler::$initialized = false
staticprotected

Definition at line 41 of file ChromePHPHandler.php.

◆ $json

Monolog\Handler\ChromePHPHandler::$json
staticprotected
Initial value:
= array(
'version' => self::VERSION,
'columns' => array('label', 'log', 'backtrace', 'type'),
'rows' => array(),
)

Definition at line 52 of file ChromePHPHandler.php.

Referenced by Monolog\Handler\ChromePHPHandler\send().

◆ $overflowed

Monolog\Handler\ChromePHPHandler::$overflowed = false
staticprotected

Definition at line 50 of file ChromePHPHandler.php.

◆ $sendHeaders

Monolog\Handler\ChromePHPHandler::$sendHeaders = true
staticprotected

Definition at line 58 of file ChromePHPHandler.php.

◆ HEADER_NAME

const Monolog\Handler\ChromePHPHandler::HEADER_NAME = 'X-ChromeLogger-Data'

Header name.

Definition at line 34 of file ChromePHPHandler.php.

◆ USER_AGENT_REGEX

const Monolog\Handler\ChromePHPHandler::USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}'

Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+)

Definition at line 39 of file ChromePHPHandler.php.

◆ VERSION

const Monolog\Handler\ChromePHPHandler::VERSION = '4.0'

The documentation for this class was generated from the following file: