PHP Class lithium\analysis\logger\adapter\FirePhp
This allows you to inspect native PHP values and objects inside the FireBug console.
Because this adapter interacts directly with the
Response object, some additional code is
required to use it. The simplest way to achieve this is to add a filter to the
Dispatcher. For
example, the following can be placed in a bootstrap file:
{{{
use lithium\action\Dispatcher;
use lithium\analysis\Logger;
Logger::config(array(
'default' => array('adapter' => 'FirePhp')
));
Dispatcher::applyFilter('_call', function($self, $params, $chain) {
if (isset($params['callable']->response)) {
Logger::adapter('default')->bind($params['callable']->response);
}
return $chain->next($self, $params, $chain);
});
}}}
This will cause the message and other debug settings added to the header of the
response, where FirePHP is able to locate and print it accordingly. As this adapter
implements the protocol specification directly, you don't need another vendor library to
use it.
Now, in you can use the logger in your application code (like controllers, views and models).
{{{
class PagesController extends \lithium\action\Controller {
public function view() {
...
Logger::error("Something bad happened!");
...
}
}
}}}
Because this adapter also has a queue implemented, it is possible to log messages even when the
Response object is not yet generated. When it gets generated (and bound), all queued messages
get flushed instantly.
Because FirePHP is not a conventional logging destination like a file or a database, you can
pass everything (except resources) to the logger and inspect it further in FirePHP. In fact,
every message that is passed will be encoded via
json_encode(), so check out this built-in
method for more information on how your message will be encoded.
{{{
Logger::debug(array('debug' => 'me));
Logger::debug(new \lithium\action\Response());
}}}
Mostrar archivo
Open project: unionofrad/lithium
Protected Properties
Property |
Type |
Description |
|
$_counter |
integer |
This self-incrementing counter allows the user to log more than one message per request. |
|
$_headers |
array |
These headers are specified by FirePHP and get added as headers to the response. |
|
$_levels |
array |
This is a mapping table that maps Lithium log levels to FirePHP log levels as they
do not correlate directly and FirePHP only accepts a distinct set. |
|
$_queue |
|
Contains messages that have been written to the log before the bind() call. |
|
$_response |
|
Holds the response object where the headers will be inserted. |
|
Public Methods
Method |
Description |
|
bind ( object $response ) : void |
Binds the response object to the logger and sets the required Wildfire
protocol headers. |
|
write ( string $priority, string $message ) : boolean |
Appends a log message to the response header for FirePHP. |
|
Protected Methods
Method |
Description |
|
_format ( string $type, string $message ) : array |
Generates a string representation of the type and message, suitable for FirePHP. |
|
_write ( array $message ) : array | void |
Helper method that writes the message to the header of a bound Response object. If no
Response object is bound when this method is called, it is stored in a message queue. |
|
Method Details
_write()
protected method
Helper method that writes the message to the header of a bound Response object. If no
Response object is bound when this method is called, it is stored in a message queue.
protected _write ( array $message ) : array | void |
$message |
array |
A message containing the key and the content to store. |
return |
array | void |
The queued message when no `Response` object was bound. |
Binds the response object to the logger and sets the required Wildfire
protocol headers.
public bind ( object $response ) : void |
$response |
object |
An instance of a response object (usually `lithium\action\Response`)
with HTTP request information. |
return |
void |
|
Appends a log message to the response header for FirePHP.
public write ( string $priority, string $message ) : boolean |
$priority |
string |
Represents the message priority. |
$message |
string |
Contains the actual message to store. |
return |
boolean |
Always returns `true`. Note that in order for message-writing to take effect,
the adapter must be bound to the `Response` object instance associated with
the current request. See the `bind()` method. |
Property Details
$_counter protected_oe property
This self-incrementing counter allows the user to log more than one message per request.
protected int $_counter |
return |
integer |
|
$_levels protected_oe property
This is a mapping table that maps Lithium log levels to FirePHP log levels as they
do not correlate directly and FirePHP only accepts a distinct set.
protected array $_levels |
return |
array |
|
$_queue protected_oe property
Contains messages that have been written to the log before the bind() call.
$_response protected_oe property
Holds the response object where the headers will be inserted.