Search by

fadilxcoder / chrome-php-logger

fadilxcoder

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

Package info

github.com/fadilxcoder/chrome-php-packagist

pkg:composer/fadilxcoder/chrome-php-logger

Statistics

Installs: 178 058

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0 2026-11-04 14:40 UTC

This package is auto-updated.

Last update: 2026-11-04 14:40:57 UTC


README

Chrome Logger is a Google Chrome extension for debugging server side applications in the Chrome console.

Most languages include their own logging capabilities, but sometimes it is easier to see your logs right in the browser.

developer developer

  • Install the Google Chrome extension
  • Click the extension icon in the browser to enable it for the current tab's domain

Installation

composer require fadilxcoder/chrome-php-logger

Requires PHP 7.2 or newer. The class is autoloaded as Logger\Chrome\ChromePhp (PSR-4).

Usage

use Logger\Chrome\ChromePhp;

ChromePhp::log('hello world');
ChromePhp::log($_SERVER);                       // arrays and objects are rendered as expandable data
ChromePhp::info('just info');
ChromePhp::warn('something went wrong!');
ChromePhp::error('it broke');

ChromePhp::group('Request');
ChromePhp::log('inside the group');
ChromePhp::groupEnd();

ChromePhp::table(array(array('id' => 1, 'name' => 'a')));

Every method accepts an unlimited number of arguments:

ChromePhp::log($user, $order, $config);

Configuration

Settings are available through the singleton:

use Logger\Chrome\ChromePhp;

// Number of stack frames to skip when reporting the log's source line (default 1).
ChromePhp::getInstance()->addSetting(ChromePhp::BACKTRACE_LEVEL, 2);

// Disable logging completely (useful in production).
ChromePhp::setEnabled(false);

// Defer header encoding until you flush manually (recommended for high-volume logging).
ChromePhp::getInstance()->addSetting(ChromePhp::AUTO_FLUSH, false);
ChromePhp::log('first');
ChromePhp::log('second');
ChromePhp::getInstance()->flush();   // must run before any output is sent

How it works

Each log row is converted, tagged with its source file/line, and appended to a buffer. The buffer is serialized to JSON, base64 encoded, and written to the X-ChromeLogger-Data response header, which the Chrome Logger extension reads.

Notes

  • Log before output. Headers cannot be modified after the response starts, so call flush() (or rely on the default immediate mode) before echoing any output.
  • AUTO_FLUSH writes the header on every call. Setting it to false encodes once, which is much faster for loops with many log calls, but you must call flush() yourself before output begins.
  • Objects are flattened recursively, including private/protected properties, with cycle detection. Property metadata is cached per class.
  • CLI is supported, but headers are no-ops outside a web request.

Click for more information.