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?
Try this:
$log->addWarning('Foo: ' . var_export($data, true));
The best approach ( from the 2nd half of Felix's answer ) for an array is:
$log->addWarning('Foo:' , $data);
The AddWarning will accept an array as the 2nd parameter and format it properly in the browser.
Using var_export will convert to a string and not format the array properly in the browser console.
Also, you can try this:
$log->addWarning('Foo: ' . print_r($data, true));
Or
$log->addWarning('Foo:' , $data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With