ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Monolog\Handler\PHPConsoleHandler Class Reference

Monolog handler for Google Chrome extension "PHP Console". More...

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

Public Member Functions

 __construct (array $options=array(), Connector $connector=null, $level=Logger::DEBUG, $bubble=true)
 
 getConnector ()
 
 getOptions ()
 
 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...
 
 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...
 

Protected Member Functions

 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 getDefaultFormatter ()
 Gets the default formatter.
Returns
FormatterInterface
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...
 

Private Member Functions

 initOptions (array $options)
 
 initConnector (Connector $connector=null)
 
 handleDebugRecord (array $record)
 
 handleExceptionRecord (array $record)
 
 handleErrorRecord (array $record)
 
 getRecordTags (array &$record)
 

Private Attributes

 $options
 
 $connector
 

Additional Inherited Members

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

Detailed Description

Monolog handler for Google Chrome extension "PHP Console".

Display PHP error/debug log messages in Google Chrome console and notification popups, executes PHP code remotely

Usage:

  1. Install Google Chrome extension https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef
  2. See overview https://github.com/barbushin/php-console#overview
  3. Install PHP Console library https://github.com/barbushin/php-console#installation
  4. Example (result will looks like http://i.hizliresim.com/vg3Pz4.png)

    $logger = new \Monolog\Logger('all', array(new \Monolog\Handler\PHPConsoleHandler())); \Monolog\ErrorHandler::register($logger); echo $undefinedVar; $logger->addDebug('SELECT * FROM users', array('db', 'time' => 0.012)); PC::debug($_SERVER); // PHP Console debugger for any type of vars

Author
Sergey Barbushin https://www.linkedin.com/in/barbushin

Definition at line 40 of file PHPConsoleHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\PHPConsoleHandler::__construct ( array  $options = array(),
Connector  $connector = null,
  $level = Logger::DEBUG,
  $bubble = true 
)
Parameters
array$optionsSee \Monolog\Handler\PHPConsoleHandler$options for more details
Connector | null$connectorInstance of \PhpConsole\Connector class (optional)
int$level
bool$bubble
Exceptions
Exception

Definition at line 75 of file PHPConsoleHandler.php.

76 {
77 if (!class_exists('PhpConsole\Connector')) {
78 throw new Exception('PHP Console library not found. See https://github.com/barbushin/php-console#installation');
79 }
80 parent::__construct($level, $bubble);
81 $this->options = $this->initOptions($options);
82 $this->connector = $this->initConnector($connector);
83 }
initConnector(Connector $connector=null)

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\PHPConsoleHandler\$connector, Monolog\Handler\AbstractHandler\$level, Monolog\Handler\PHPConsoleHandler\$options, Monolog\Handler\PHPConsoleHandler\initConnector(), and Monolog\Handler\PHPConsoleHandler\initOptions().

+ Here is the call graph for this function:

Member Function Documentation

◆ getConnector()

Monolog\Handler\PHPConsoleHandler::getConnector ( )

Definition at line 150 of file PHPConsoleHandler.php.

151 {
152 return $this->connector;
153 }

References Monolog\Handler\PHPConsoleHandler\$connector.

◆ getDefaultFormatter()

Monolog\Handler\PHPConsoleHandler::getDefaultFormatter ( )
protected

Gets the default formatter.

Returns
FormatterInterface

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 238 of file PHPConsoleHandler.php.

239 {
240 return new LineFormatter('%message%');
241 }

◆ getOptions()

Monolog\Handler\PHPConsoleHandler::getOptions ( )

Definition at line 155 of file PHPConsoleHandler.php.

156 {
157 return $this->options;
158 }

References Monolog\Handler\PHPConsoleHandler\$options.

◆ getRecordTags()

Monolog\Handler\PHPConsoleHandler::getRecordTags ( array &  $record)
private

Definition at line 214 of file PHPConsoleHandler.php.

215 {
216 $tags = null;
217 if (!empty($record['context'])) {
218 $context =& $record['context'];
219 foreach ($this->options['debugTagsKeysInContext'] as $key) {
220 if (!empty($context[$key])) {
221 $tags = $context[$key];
222 if ($key === 0) {
223 array_shift($context);
224 } else {
225 unset($context[$key]);
226 }
227 break;
228 }
229 }
230 }
231
232 return $tags ?: strtolower($record['level_name']);
233 }

Referenced by Monolog\Handler\PHPConsoleHandler\handleDebugRecord().

+ Here is the caller graph for this function:

◆ handle()

Monolog\Handler\PHPConsoleHandler::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.
}}

Reimplemented from Monolog\Handler\AbstractProcessingHandler.

Definition at line 160 of file PHPConsoleHandler.php.

161 {
162 if ($this->options['enabled'] && $this->connector->isActiveClient()) {
163 return parent::handle($record);
164 }
165
166 return !$this->bubble;
167 }

References Monolog\Handler\AbstractHandler\$bubble.

◆ handleDebugRecord()

Monolog\Handler\PHPConsoleHandler::handleDebugRecord ( array  $record)
private

Definition at line 186 of file PHPConsoleHandler.php.

187 {
188 $tags = $this->getRecordTags($record);
189 $message = $record['message'];
190 if ($record['context']) {
191 $message .= ' ' . json_encode($this->connector->getDumper()->dump(array_filter($record['context'])));
192 }
193 $this->connector->getDebugDispatcher()->dispatchDebug($message, $tags, $this->options['classesPartialsTraceIgnore']);
194 }

References Monolog\Handler\PHPConsoleHandler\getRecordTags().

Referenced by Monolog\Handler\PHPConsoleHandler\write().

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

◆ handleErrorRecord()

Monolog\Handler\PHPConsoleHandler::handleErrorRecord ( array  $record)
private

Definition at line 201 of file PHPConsoleHandler.php.

202 {
203 $context = $record['context'];
204
205 $this->connector->getErrorsDispatcher()->dispatchError(
206 isset($context['code']) ? $context['code'] : null,
207 isset($context['message']) ? $context['message'] : $record['message'],
208 isset($context['file']) ? $context['file'] : null,
209 isset($context['line']) ? $context['line'] : null,
210 $this->options['classesPartialsTraceIgnore']
211 );
212 }

Referenced by Monolog\Handler\PHPConsoleHandler\write().

+ Here is the caller graph for this function:

◆ handleExceptionRecord()

Monolog\Handler\PHPConsoleHandler::handleExceptionRecord ( array  $record)
private

Definition at line 196 of file PHPConsoleHandler.php.

197 {
198 $this->connector->getErrorsDispatcher()->dispatchException($record['context']['exception']);
199 }

Referenced by Monolog\Handler\PHPConsoleHandler\write().

+ Here is the caller graph for this function:

◆ initConnector()

Monolog\Handler\PHPConsoleHandler::initConnector ( Connector  $connector = null)
private

Definition at line 95 of file PHPConsoleHandler.php.

96 {
97 if (!$connector) {
98 if ($this->options['dataStorage']) {
99 Connector::setPostponeStorage($this->options['dataStorage']);
100 }
101 $connector = Connector::getInstance();
102 }
103
104 if ($this->options['registerHelper'] && !Helper::isRegistered()) {
105 Helper::register();
106 }
107
108 if ($this->options['enabled'] && $connector->isActiveClient()) {
109 if ($this->options['useOwnErrorsHandler'] || $this->options['useOwnExceptionsHandler']) {
110 $handler = Handler::getInstance();
111 $handler->setHandleErrors($this->options['useOwnErrorsHandler']);
112 $handler->setHandleExceptions($this->options['useOwnExceptionsHandler']);
113 $handler->start();
114 }
115 if ($this->options['sourcesBasePath']) {
116 $connector->setSourcesBasePath($this->options['sourcesBasePath']);
117 }
118 if ($this->options['serverEncoding']) {
119 $connector->setServerEncoding($this->options['serverEncoding']);
120 }
121 if ($this->options['password']) {
122 $connector->setPassword($this->options['password']);
123 }
124 if ($this->options['enableSslOnlyMode']) {
125 $connector->enableSslOnlyMode();
126 }
127 if ($this->options['ipMasks']) {
128 $connector->setAllowedIpMasks($this->options['ipMasks']);
129 }
130 if ($this->options['headersLimit']) {
131 $connector->setHeadersLimit($this->options['headersLimit']);
132 }
133 if ($this->options['detectDumpTraceAndSource']) {
134 $connector->getDebugDispatcher()->detectTraceAndSource = true;
135 }
136 $dumper = $connector->getDumper();
137 $dumper->levelLimit = $this->options['dumperLevelLimit'];
138 $dumper->itemsCountLimit = $this->options['dumperItemsCountLimit'];
139 $dumper->itemSizeLimit = $this->options['dumperItemSizeLimit'];
140 $dumper->dumpSizeLimit = $this->options['dumperDumpSizeLimit'];
141 $dumper->detectCallbacks = $this->options['dumperDetectCallbacks'];
142 if ($this->options['enableEvalListener']) {
143 $connector->startEvalRequestsListener();
144 }
145 }
146
147 return $connector;
148 }

References Monolog\Handler\PHPConsoleHandler\$connector.

Referenced by Monolog\Handler\PHPConsoleHandler\__construct().

+ Here is the caller graph for this function:

◆ initOptions()

Monolog\Handler\PHPConsoleHandler::initOptions ( array  $options)
private

Definition at line 85 of file PHPConsoleHandler.php.

86 {
87 $wrongOptions = array_diff(array_keys($options), array_keys($this->options));
88 if ($wrongOptions) {
89 throw new Exception('Unknown options: ' . implode(', ', $wrongOptions));
90 }
91
92 return array_replace($this->options, $options);
93 }

References Monolog\Handler\PHPConsoleHandler\$options.

Referenced by Monolog\Handler\PHPConsoleHandler\__construct().

+ Here is the caller graph for this function:

◆ write()

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

Writes the record down to the log of the implementing handler.

Parameters
array$record
Returns
void

Reimplemented from Monolog\Handler\AbstractProcessingHandler.

Definition at line 175 of file PHPConsoleHandler.php.

176 {
177 if ($record['level'] < Logger::NOTICE) {
178 $this->handleDebugRecord($record);
179 } elseif (isset($record['context']['exception']) && $record['context']['exception'] instanceof Exception) {
180 $this->handleExceptionRecord($record);
181 } else {
182 $this->handleErrorRecord($record);
183 }
184 }
const NOTICE
Uncommon events.
Definition: Logger.php:44

References Monolog\Handler\PHPConsoleHandler\handleDebugRecord(), Monolog\Handler\PHPConsoleHandler\handleErrorRecord(), Monolog\Handler\PHPConsoleHandler\handleExceptionRecord(), and Monolog\Logger\NOTICE.

+ Here is the call graph for this function:

Field Documentation

◆ $connector

◆ $options

Monolog\Handler\PHPConsoleHandler::$options
private
Initial value:
= array(
'enabled' => true,
'classesPartialsTraceIgnore' => array('Monolog\\'),
'debugTagsKeysInContext' => array(0, 'tag'),
'useOwnErrorsHandler' => false,
'useOwnExceptionsHandler' => false,
'sourcesBasePath' => null,
'registerHelper' => true,
'serverEncoding' => null,
'headersLimit' => null,
'password' => null,
'enableSslOnlyMode' => false,
'ipMasks' => array(),
'enableEvalListener' => false,
'dumperDetectCallbacks' => false,
'dumperLevelLimit' => 5,
'dumperItemsCountLimit' => 100,
'dumperItemSizeLimit' => 5000,
'dumperDumpSizeLimit' => 500000,
'detectDumpTraceAndSource' => false,
'dataStorage' => null,
)

Definition at line 42 of file PHPConsoleHandler.php.

Referenced by Monolog\Handler\PHPConsoleHandler\__construct(), Monolog\Handler\PHPConsoleHandler\getOptions(), and Monolog\Handler\PHPConsoleHandler\initOptions().


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