ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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...
 

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/)

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

Definition at line 22 of file ChromePHPHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\ChromePHPHandler::__construct (   $level = Logger::DEBUG,
  $bubble = true 
)
Parameters
integer$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 57 of file ChromePHPHandler.php.

58 {
59 parent::__construct($level, $bubble);
60 if (!function_exists('json_encode')) {
61 throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s ChromePHPHandler');
62 }
63 }

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 184 of file ChromePHPHandler.php.

185 {
186 if ('sendHeaders' !== $property) {
187 throw new \InvalidArgumentException('Undefined property '.$property);
188 }
189
190 return static::$sendHeaders;
191 }

◆ __set()

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

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

Definition at line 196 of file ChromePHPHandler.php.

197 {
198 if ('sendHeaders' !== $property) {
199 throw new \InvalidArgumentException('Undefined property '.$property);
200 }
201
202 static::$sendHeaders = $value;
203 }

◆ getDefaultFormatter()

Monolog\Handler\ChromePHPHandler::getDefaultFormatter ( )
protected

Gets the default formatter.

Returns
FormatterInterface

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 89 of file ChromePHPHandler.php.

90 {
91 return new ChromePHPFormatter();
92 }

◆ 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 68 of file ChromePHPHandler.php.

69 {
70 $messages = array();
71
72 foreach ($records as $record) {
73 if ($record['level'] < $this->level) {
74 continue;
75 }
76 $messages[] = $this->processRecord($record);
77 }
78
79 if (!empty($messages)) {
80 $messages = $this->getFormatter()->formatBatch($messages);
81 self::$json['rows'] = array_merge(self::$json['rows'], $messages);
82 $this->send();
83 }
84 }
getFormatter()
{Gets the formatter.FormatterInterface}
processRecord(array $record)
Processes a record.
$messages
Definition: en-x-test.php:7
$records
Definition: simple_test.php:17

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 172 of file ChromePHPHandler.php.

173 {
174 if (empty($_SERVER['HTTP_USER_AGENT'])) {
175 return false;
176 }
177
178 return preg_match('{\bChrome/\d+[\.\d+]*\b}', $_SERVER['HTTP_USER_AGENT']);
179 }
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 113 of file ChromePHPHandler.php.

114 {
115 if (self::$overflowed || !self::$sendHeaders) {
116 return;
117 }
118
119 if (!self::$initialized) {
120 self::$initialized = true;
121
122 self::$sendHeaders = $this->headersAccepted();
123 if (!self::$sendHeaders) {
124 return;
125 }
126
127 self::$json['request_uri'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
128 }
129
130 $json = @json_encode(self::$json);
131 $data = base64_encode(utf8_encode($json));
132 if (strlen($data) > 240*1024) {
133 self::$overflowed = true;
134
135 $record = array(
136 'message' => 'Incomplete logs, chrome header size limit reached',
137 'context' => array(),
138 'level' => Logger::WARNING,
139 'level_name' => Logger::getLevelName(Logger::WARNING),
140 'channel' => 'monolog',
141 'datetime' => new \DateTime(),
142 'extra' => array(),
143 );
144 self::$json['rows'][count(self::$json['rows']) - 1] = $this->getFormatter()->format($record);
145 $json = @json_encode(self::$json);
146 $data = base64_encode(utf8_encode($json));
147 }
148
149 if (trim($data) !== '') {
150 $this->sendHeader(self::HEADER_NAME, $data);
151 }
152 }
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:388
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
$data

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 160 of file ChromePHPHandler.php.

161 {
162 if (!headers_sent() && self::$sendHeaders) {
163 header(sprintf('%s: %s', $header, $content));
164 }
165 }
$header

References $header.

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 101 of file ChromePHPHandler.php.

102 {
103 self::$json['rows'][] = $record['formatted'];
104
105 $this->send();
106 }

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 34 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 45 of file ChromePHPHandler.php.

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

◆ $overflowed

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

Definition at line 43 of file ChromePHPHandler.php.

◆ $sendHeaders

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

Definition at line 51 of file ChromePHPHandler.php.

◆ HEADER_NAME

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

Header name.

Definition at line 32 of file ChromePHPHandler.php.

◆ VERSION

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

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