rame0/chromephp

Log variables to the Chrome console (via Chrome Logger Google Chrome extension).

5.0.3-patch1 2021-05-17 16:29 UTC

This package is auto-updated.

Last update: 2024-05-17 22:50:26 UTC


README

ChromePhp is a PHP library for the Chrome Logger Google Chrome extension.

This library allows you to log data to the Chrome console.

Requirements

  • PHP 7.4 or later

Installation

  1. Install the browser extension from: https://chrome.google.com/extensions/detail/noaneddfkdjfnfdakjjmocngnfkfehhd
  2. Click the extension icon in the browser to enable it for the current tab's domain
  3. Install ChromePhp

It's not recommended to use this library on production!

Install as dev dependency:

    composer require --dev rame0/chromephp

Install as prod dependency:

    composer require rame0/chromephp

Log some data

// First require autoload
require __DIR__ . '/vendor/autoload.php';
$logger = new ChromePhp();

Log

$logger->log('Some log message');
$logger->log('Some other log message');

Result

1

Warning

$logger->warn('Some warning');
$logger->warn('Some other warning');

Result

2

Error

$logger->error('Some error');
$logger->error('Some other error');

Result

3

Table

$table = [];
for ($i = 0; $i < 5; $i++) {
    $row = [];
    for ($c = 1; $c < 3; $c++) {
        $row['Col ' . $c] = $i;
    }
    $table[] = $row;
}
$logger->table($table);

Result

4

Exception

$ex = new InvalidArgumentException('Some exception!');
$logger->exception($ex);

try{
    new PDO('asdf');
}catch (PDOException $ex){
    $logger->exception($ex);
}

Result

5

More information can be found here: http://www.chromelogger.com