2017 © Pedro Peláez
 

library mylogphp

MyLogPHP is a single PHP class to easily keep log files in CSV format.

image

llagerlof/mylogphp

MyLogPHP is a single PHP class to easily keep log files in CSV format.

  • Tuesday, April 10, 2018
  • by llagerlof
  • Repository
  • 6 Watchers
  • 28 Stars
  • 53 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 1 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

MyLogPHP

MyLogPHP is a single PHP class to easily keep log files in CSV format., (*1)

Install the latest version

Direct download (just include this file in your script)

MyLogPHP.class.php (1.2.19)
, (*2)

Or you can use Composer

Edit your project's composer.json and add the required package: "llagerlof/mylogphp": "dev-master", (*3)

Eg:, (*4)

{
    "name": "your/project",
    "require": {
        "llagerlof/mylogphp": "dev-master"
    }
}

How to read the generated log file

Any CSV reader can be used to open the generated logs, but If you need a recomendation, try the CSVFileView or LogExpert. Both can parse/show the CSV columns and watch realtime changes in log file (like tail on Linux)., (*5)

Features

  • One single file to rule them all!
  • Super easy start.
  • Two extra columns are automatically added in the CSV: the number of execution line and the path of host script where the log was called.
  • Minimum PHP version: 5.3

Want more features? I am listening!

Create an issue in https://github.com/llagerlof/MyLogPHP/issues/new, (*6)

Quick start

Include in your script the file "MyLogPHP.class.php" (not needed if you are using the composer version)., (*7)

include('MyLogPHP.class.php');

Instantiate the object. Optionally you can pass the log file name and the separator as a parameter. Default log file name is "_MyLogPHP-1.2.log.csv" in current folder, and default separator is comma (,)., (*8)

$log = new MyLogPHP\MyLogPHP('./log/debug.log.csv');

Make sure the directory where the log will be created is writable., (*9)

Call method "info", "warning", "error" or "debug" to write the messages. The first parameter is the message, the optional second parameter is a free tag at your choice to help you filter the log when opened by an spreadsheet software, like OpenOffice Calc or Microsoft Excel., (*10)

$log->info('This message will be logged in the file debug.log.csv','TIP');

That's it!, (*11)

Examples

$log = new MyLogPHP\MyLogPHP();

$log->info('The program starts here.');

$log->warning('This problem can affect the program logic');

$log->warning('Use this software at your own risk!');

$log->info('Lawrence Lagerlof','AUTHOR');

$log->info('Asimov rulez','FACT');

$log->error('Everything crash and burn','IE');

$log->debug("select * from table",'DB');

Writing a variable content to file "_OUT_MyLogPHP.txt", (*12)

\MyLogPHP\MyLogPHP::out($data);

\MyLogPHP\MyLogPHP::out($data, array('LABEL' => 'variable $data');

\MyLogPHP\MyLogPHP::out($data, 'variable $data'); // same as above

\MyLogPHP\MyLogPHP::out($data, array('LABEL' => 'variable $data', 'WRITE_MODE' => MyLogPHP::OVERWRITE));

\MyLogPHP\MyLogPHP::out($data, array('LABEL' => 'variable $data', 'WRITE_MODE' => MyLogPHP::APPEND)); // WRITE_MODE can be OVERWRITE or APPEND (APPEND is default)

Changelog

1.2.19 * Read the configuration file only once per instance., (*13)

1.2.18 * Namespace added., (*14)

1.2.17 * Fixed a debug_backtrace problem when used in Laravel application., (*15)

1.2.16 * Put an optional config file (MyLogPHP.conf in the same directory of the class) with one line containing "enabled=false" to disable logging., (*16)

1.2.15 * Changed output format of out() method., (*17)

1.2.14 * Added method name to output of the out() method., (*18)

1.2.13 * Added the file and execution line info to output of the out() method., (*19)

1.2.12 * You can define a $_SESSION variable to set where the file will be created by the out() method., (*20)

1.2.11 * out() method is now static., (*21)

1.2.10 * Can pass a string to act as LABEL to the second parameter of out() method., (*22)

1.2.9 * Removed supressed warnings from variable $headers and date() functions., (*23)

1.2.8 * Add more options and verbosity to out() method., (*24)

1.2.7 * New method out() allow append a variable value to the end of the file _OUT_MyLogPHP.txt, (*25)

1.2.6 * Class updated for PHP 7 (thanks @clintre)., (*26)

1.2.5 * Solved a bug that was preventing the replacement of consecutives spaces and tabs for one space., (*27)

1.2.4 * All consecutives spaces and tabs are removed from output., (*28)

1.2.3 * PHPDOC comment style applied to the class. * An issue with the newer version of PHP and the date() function was solved., (*29)

1.2.2 * Line breaks of VALUE field are converted to spaces to prevent some CSV readers wrongly interpret line breaks as new CSV lines. * The VALUE field now is trimmed before output., (*30)

1.2.1 * Disable a warning message if an internal variable is not set., (*31)

1.2 * Two columns added in CSV output: LINE and FILE., (*32)

1.1 * Added support to choose the field separator. Comma is still the default., (*33)

The Versions

10/04 2018

dev-master

9999999-dev https://github.com/llagerlof/MyLogPHP

MyLogPHP is a single PHP class to easily keep log files in CSV format.

  Sources   Download

BSD-3-Clause

logger log csv php logging