Skip to content
This repository was archived by the owner on Aug 18, 2022. It is now read-only.

josantonius/php-logger

Repository files navigation

PHP Logger library

Latest Stable Version Total Downloads Latest Unstable Version License

Spanish version

Php library to create logs easily and store them in Json format.



Take a look at the code


Installation

The preferred way to install this extension is through composer.

To install PHP Logger library, simply:

$ composer require Josantonius/Logger 

The previous command will only install the necessary files, if you prefer to download the entire source code (including tests, vendor folder, exceptions not used, docs...) you can use:

$ composer require Josantonius/Logger --prefer-source 

Or you can also clone the complete repository with Git:

$ git clone https://github.com/Josantonius/PHP-Logger.git 

Requirements

This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.

Quick Start and Examples

To use this class, simply:

require __DIR__ . '/vendor/autoload.php'; use Josantonius\Logger\Logger;

Available Methods

Available methods in this library:

Logger::save(); Logger::storeLogs();

Usage

Example of use for this library:

<?php require __DIR__ . '/vendor/autoload.php'; use Josantonius\Logger\Logger; new Logger(); Logger::save('JOIN', 800, 100, 'Your message here', __LINE__, __FILE__); Logger::save('INFO', 801, 200, 'Your message here', __LINE__, __FILE__); Logger::save('WARNING', 802, 300, 'Your message here', __LINE__, __FILE__); Logger::save('ERROR', 803, 400, 'Your message here', __LINE__, __FILE__); Logger::save('FATAL', 804, 500, 'Your message here', __LINE__, __FILE__); Logger::storeLogs(); echo '<pre>'; var_dump(Logger::$logs); echo '</pre>'; /* array(1) {  [0]=>  array(14) {  ["ip"]=>  string(3) "158.54.12.100"  ["uri"]=>  string(5) "/folder/"  ["referer"]=>  string(7) "http://www.referer.es/"  ["remote-port"]=>  int(47290)  ["ip-server"]=>  string(3) "188.254.112.200"  ["user-agent"]=>  string(133) "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/5.36 (KHTML, like Gecko) Ubuntu Chromium/55.0.23.87 Chrome/55.0.23.87 Safari/5.36"  ["type"]=>  string(4) "join"  ["state"]=>  int(800)  ["code"]=>  string(3) "100"  ["message"]=>  string(17) "Visit the page"  ["line"]=>  int(572)  ["file"]=>  string(44) "/var/www/localhost/public_html/folder/index.php"  ["hour"]=>  string(8) "20:58:18"  ["date"]=>  string(10) "2017-01-21"  } } */

Tests

To use the test class, simply:

<?php $loader = require __DIR__ . '/vendor/autoload.php'; $loader->addPsr4('Josantonius\\Logger\\Tests\\', __DIR__ . '/vendor/josantonius/logger/tests'); use Josantonius\Logger\Tests\LoggerTest;

Available test methods in this library:

LoggerTest->testSaveLog(); LoggerTest->testSaveLogWithFilepath(); LoggerTest->testSaveLogWithLimitLogsNumber(); LoggerTest->testSaveLogWithUserIP(); LoggerTest->testSaveLogWithUserCustomStates(); LoggerTest->testSaveLogWithUserCustomParams(); LoggerTest->testDisableLogs(); LoggerTest->testDisableLogsByState(); LoggerTest->testGetLogs(); LoggerTest->testGetLogsFromCustomPath(); LoggerTest->testExceptionCouldCreatePath();

Contribute

  1. Check for open issues or open a new issue to start a discussion around a bug or feature.
  2. Fork the repository on GitHub to start making your changes.
  3. Write one or more tests for the new feature or that expose the bug.
  4. Make code changes to implement the feature or fix the bug.
  5. Send a pull request to get your changes merged and published.

This is intended for large and long-lived objects.

Repository

All files in this repository were created and uploaded automatically with Reposgit Creator.

License

This project is licensed under MIT license. See the LICENSE file for more info.

Copyright

2017 Josantonius, josantonius.com

If you find it useful, let me know 😉

You can contact me on Twitter or through my email.

About

PHP library to create logs easily and store them in JSON format.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published