PHP Classes

Simple Logger: Log messages and view log filtered files

Recommend this page to a friend!
  Info   View files Example   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 71%Total: 383 All time: 6,698 This week: 358Up
Version License PHP version Categories
simple-logger 1.0.2MIT/X Consortium ...5.4PHP 5, Console, Logging, Traits
Description 

Author

This package can log messages and view log filtered files.

It provides a base logger class that is extended by a class that sends log messages to files.

A separate class can list and filter logs from the command line according to given criteria like the log level of each message, log message date and text in the log message.

Innovation Award
PHP Programming Innovation award nominee
September 2016
Number 3


Prize: One subscription to the PDF edition of the PHP Architect magazine
Logging actions is an important functionality that many applications implement.

There are many components to implement logging, but this package goes further by providing a means to search and filter logs according to a given criteria of interest like the log level, date or text in the log message.

Manuel Lemos
Picture of Joseluis Laso
  Performance   Level  
Name: Joseluis Laso <contact>
Classes: 16 packages by
Country: Spain Spain
Age: 56
All time rank: 92519 in Spain Spain
Week rank: 91 Up4 in Spain Spain Up
Innovation award
Innovation award
Nominee: 6x

Winner: 2x

Example

<?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");

Logger::debug(array(
   
'title' => 'This is the title',
   
'data' => 'more data',
));

$a = 1234/ $b;

set_error_handler('error_handler');

function
error_handler($e)
{
   
Logger::error($e);
}

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


Details

Build Status

simple-logger

A simple logger system

Installation

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
logger:
    path: "%project_dir%/cache/logger-%date%.log"
    levels: error,info,debug    
    date_format: "Y-m-d"

Commands

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`

<?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");

Logger::debug(array(
    'title' => 'This is the title',
    'data' => 'more data',
));

$a = 1234/ $b;

set_error_handler('error_handler');

function error_handler($e)
{
    Logger::error($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 (https://github.com/jlaso/simple-stats-demo/tree/master/app)[https://github.com/jlaso/simple-stats-demo/tree/master/app]

<?php

namespace App\Command;

use JLaso\SimpleLogger\Command\FilterCommand;

class FilterLogCommand extends FilterCommand
{

}

add it to app/console

#!/usr/bin/env php
<?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();
$application->addCommands(
    array(
        new PostDeployCommand(),
        new FilterLogCommand(),    <======
    )
);
$application->run();

Changelog

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


  Files folder image Files  
File Role Description
Files folder imagecache (1 file)
Files folder imagesrc (6 files, 1 directory)
Files folder imageTests (3 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file config-simple-logger.yml.dist Data Auxiliary data
Accessible without login Plain text file demo.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  cache  
File Role Description
  Accessible without login Plain text file .gitkept Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageCommand (1 file)
  Accessible without login Plain text file BaseConfig.php Class Class source
  Accessible without login Plain text file BaseLogger.php Class Class source
  Accessible without login Plain text file console Example Example script
  Accessible without login Plain text file LoggerInterface.php Class Class source
  Accessible without login Plain text file PlainFileLogger.php Class Class source
  Accessible without login Plain text file SingletonTrait.php Class Class source

  Files folder image Files  /  src  /  Command  
File Role Description
  Accessible without login Plain text file FilterCommand.php Class Class source

  Files folder image Files  /  Tests  
File Role Description
  Accessible without login Plain text file AbstractTestCase.php Class Class source
  Accessible without login Plain text file ConfigTest.php Class Class source
  Accessible without login Plain text file PlainLoggerTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:383
This week:0
All time:6,698
This week:358Up
 User Ratings  
 
 All time
Utility:87%StarStarStarStarStar
Consistency:93%StarStarStarStarStar
Documentation:87%StarStarStarStarStar
Examples:93%StarStarStarStarStar
Tests:-
Videos:-
Overall:71%StarStarStarStar
Rank:231