Monolog, how to log PHP array into console?

Ryan picture Ryan · Jun 27, 2014 · Viewed 9.3k times · Source

I am using the browser handler to log message into JS console

require_once 'vendor/autoload.php';

use Monolog\Logger;
use Monolog\Handler\BrowserConsoleHandler;

$log = new Logger('name');
$log->pushHandler(new BrowserConsoleHandler);

$data = array(1,2,3,4);

// add records to the log
$log->addWarning('Foo');

I am wondering, is it possible to log array such as $data into the console which reassemble the array content?

Answer

benJ picture benJ · Jun 27, 2014

Try this:

$log->addWarning('Foo: ' . var_export($data, true));