Fork me on GitHub

PHP Log Class

Example log file located here


This PHP class was written as a light weight, easy-to-use way to log activity to a .log file. It's designed to instantly work within any PHP project, multiple log files and complete freedom with the format of the log entries.

All 8 logging levels defined in RFC 5424 are supported (DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY) and this class implements the PSR-3 interface.

Upon refreshing this page, the example log file in the above iframe is cleared and updated with new entries.


MIT/GPL License

Follow or Fork

Open Source PHP Log class Follow this project on Github!

Basic Usage

Create a log instance for one .log file, or multiple:

$log = new Log('example.log');

// OR
$multi_logs = new Log(array(
   'default' => 'example.log', 
   'other' => 'other.log'

Add entries to a .log file:

$log->warning('Basic entry, with timestamp');
$log->warning('Entry with context', array('Meta', 'data', 'here'));   

$log->log($log::DEBUG, 'Entry with custom level');

Clear the .log file completely (use with caution).