PHP Classes
elePHPant
Icontem

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    
Last Updated Ratings Unique User Downloads Download Rankings
2016-11-14 (1 year ago) RSS 2.0 feedStarStarStarStar 73%Total: 284 This week: 1All time: 7,247 This week: 627Up
Version License PHP version Categories
simple-logger 1.0.0MIT/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
  Performance   Level  
Name: Joseluis Laso <contact>
Classes: 16 packages by
Country: Spain Spain
Age: 49
All time rank: 104820 in Spain Spain
Week rank: 177 Up6 in Spain Spain Up
Innovation award
Innovation award
Nominee: 6x

Winner: 2x

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)
  Plain text file BaseConfig.php Class Class source
  Plain text file BaseLogger.php Class Class source
  Accessible without login Plain text file console Example Example script
  Plain text file LoggerInterface.php Class Class source
  Plain text file PlainFileLogger.php Class Class source
  Plain text file SingletonTrait.php Class Class source

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

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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:284
This week:1
All time:7,247
This week:627Up
 User Ratings  
 
 All time
Utility:91%StarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:91%StarStarStarStarStar
Examples:91%StarStarStarStarStar
Tests:-
Videos:-
Overall:73%StarStarStarStar
Rank:205