Php library to create logs easily and store them in Json format.
- Installation
- Requirements
- Quick Start and Examples
- Available Methods
- Usage
- Tests
- Contribute
- Repository
- License
- Copyright
Take a look at the code
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
This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.
To use this class, simply:
require __DIR__ . '/vendor/autoload.php'; use Josantonius\Logger\Logger;
Available methods in this library:
Logger::save(); Logger::storeLogs();
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" } } */
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();
- Check for open issues or open a new issue to start a discussion around a bug or feature.
- Fork the repository on GitHub to start making your changes.
- Write one or more tests for the new feature or that expose the bug.
- Make code changes to implement the feature or fix the bug.
- Send a pull request to get your changes merged and published.
This is intended for large and long-lived objects.
All files in this repository were created and uploaded automatically with Reposgit Creator.
This project is licensed under MIT license. See the LICENSE file for more info.
2017 Josantonius, josantonius.com
If you find it useful, let me know 😉