PHP Classes


Recommend this page to a friend!
  Classes of Joseluis Laso  >  Simple Logger  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Simple Logger
Log messages and view log filtered files
Author: By
Last change: Update of
Date: 10 months ago
Size: 2,421 bytes


Class file image Download

Build Status


A simple logger system


You need only to require this package in your project `composer require jlaso/simple-logger`

Configuration (optional)

In order to let know the library where can put its database file and other things related with setup you can copy the distribution file config-simple-logger.yml.dist in the root of your project with the config-simple-logger.yml

This file contains:

# vendor/jlaso/simple-logger/config-simple-logger.yml.dist
    path: "%project_dir%/cache/logger-%date%.log"
    levels: error,info,debug    
    date_format: "Y-m-d"


In order to check log file you can use `src/console log:filter [--with=word1,word2,...] [--levels=error,info] [--date-from="2016-01-01 00:00:00"]`

Running the example

Go to terminal and start the demo example `php demo.php`


error_reporting(E_ALL & !E_WARNING);

require_once __DIR__.'/vendor/autoload.php';

use JLaso\SimpleLogger\PlainFileLogger as Logger;

$start = microtime(true);
Logger::info("This is only the start of the program");

    'title' => 'This is the title',
    'data' => 'more data',

$a = 1234/ $b;


function error_handler($e)

Logger::info('Just finishing the execution of the program in '.intval((microtime(true)-$start)*1000).' msec !');

Implementing the filter command in your app

You can see an example of how to do that ([]


namespace App\Command;

use JLaso\SimpleLogger\Command\FilterCommand;

class FilterLogCommand extends FilterCommand


add it to app/console

#!/usr/bin/env php

namespace JLaso\SimpleStats;

require_once __DIR__ . '/../vendor/autoload.php';

use App\Command\FilterLogCommand;   <======
use App\Command\PostDeployCommand;
use Symfony\Component\Console\Application;

$application = new Application();
        new PostDeployCommand(),
        new FilterLogCommand(),    <======


1.0.3 added date_format in order to have different logs names for every day

For more information send a message to info at phpclasses dot org.