Php library to create logs easily and store them in Json format.
- Installation
- Requirements
- Quick Start and Examples
- Available Methods
- Usage
- Tests
- Exception Handler
- Contribute
- Repository
- Author
- Licensing
The preferred way to install this extension is through composer.
To install PHP Logger library, simply:
$ composer require Josantonius/Logger
This library is supported by PHP versions 7.0 or higher and is compatible with HHVM versions 3.0 or higher.
To use this library in HHVM (HipHop Virtual Machine) you will have to activate the scalar types. Add the following line "hhvm.php7.scalar_types = true" in your "/etc/hhvm/php.ini".
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();
This library uses exception handler that you can customize.
- 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.
Maintained by Josantonius.
This project is licensed under MIT license. See the LICENSE file for more info.