v1.0 2017-06-18 16:39 UTC

This package is not auto-updated.

Last update: 2020-08-08 05:25:45 UTC


One Efficient & Light & Simple high performance PHP log implemention of PSR-3


Inherently cached message record using PHP object attribute.



$ composer require logger-one/logger-one

Invoke by default mode

Will using FileHandler create a log file named for %Y%m%d and appendix .log at LoggerOne root folder, ervery message as line with the original

$logger = LoggerOne\Logger::getInstance();  // Strongly recommend

$message = 'test log message {placeholder1} {placeholder2}';

$replacements = ['placeholder1' => 'Foo', 'placeholder2' => 'bar'];

$logger->info($message, $replacements);

Change FileHandler default path

$logFile = './tmp/loggerOne.log'; // Your path where you want

$handler = new LoggerOne\Handler\FileHandler($logFile);



Specific Handler & Formatter

$fooHandler = new LoggerOne\Handler\FooHandler();

$barFormatter = new LoggerOne\Formatter\BarFormatter();


$logger->info('some test log message');

Flush log message immediately

Once calling flush method will write all previous message by handler

$logger->info('some test log message')->flush();


Handler Extension Simple

Put your own MySQLHandler.php in LoggerOne\Handler folder

namespace LoggerOne\Handler;

class MySQLHandler implements Handler
    protected $db;
    protected $tableName;
    public function __construct(string $tableName, object $dbHandle = null)
        $this->tableName = $tableName;
        $this->db = $dbHandle;
    public function write($messages)
        $batchData = [];
        foreach ($messages as $level => $message) {
            $batchData[] = ['level' => $level, 'message' => $message, 'created' => time()];
        $this->db->insertBatch($this->tableName, $batchData);

Use MySQLHandler.php

$logger = new LoggerOne\Logger();

$handler = new LoggerOne\Handler\MysqlHandler($yourLogTableName, $yourDbHandle);


$logger->info('some test log message');

Formatter Extension Simple

The way just like Handler extending


  • If you have not using composer, should remember load all dependency class in your way.
  • Try to keep your handler write in batches for performace