项目作者: 00F100

项目描述 :
Package to manipulate log application
高级语言: PHP
项目地址: git://github.com/00F100/fcphp-log.git
创建时间: 2018-06-15T00:09:24Z
项目社区:https://github.com/00F100/fcphp-log

开源协议:MIT License

下载


FcPhp Log

Package to manipulate logs of application FcPhp

Build Status codecov Total Downloads

How to install

Composer:

  1. $ composer require 00f100/fcphp-log

or add in composer.json

  1. {
  2. "require": {
  3. "00f100/fcphp-log": "*"
  4. }
  5. }

How to use

Create logs easy! If $debug = false in constructor, just $log->error() and $log->warning() works…

  1. <?php
  2. use \FcPhp\Log\Log;
  3. /*
  4. Method to return instance of Log
  5. @param string $directoryOutput Directory to write logs
  6. @param string|bool $dateFormat Format of date to print log. If `false` not print date
  7. @param string $extension Extension of file log
  8. @param bool $debug Enable debug mode
  9. @return FcPhp\Log\Interfaces\ILog
  10. Log::getInstance(string $directoryOutput, $dateFormat = 'Y-m-d H:i:s', string $extension = 'log', bool $debug = false) :ILog
  11. */
  12. $log = Log::getInstance('var/log', 'Y-m-d H:i:s', 'log', true);
  13. // To error logs
  14. $log->error('message of error');
  15. // Print log: var/log/error.log
  16. // [2018-06-16 04:06:25] message of error
  17. // To warning logs
  18. $log->warning('message of warning');
  19. // Print log: var/log/warning.log
  20. // [2018-06-16 04:06:25] message of warning
  21. // To debug
  22. $log->debug('message debug');
  23. // Print log: var/log/debug.log
  24. // [2018-06-16 04:06:25] message debug
  25. // To many types
  26. $log->fooBar('message foo bar');
  27. // Print log: var/log/fooBar.log
  28. // [2018-06-16 04:06:25] message foo bar

Custom format log

  1. <?php
  2. use \FcPhp\Log\Log;
  3. $log = Log::getInstance('var/log', 'Y-m-d H:i:s', 'log', true);
  4. $log->customLog(function(string $dateTime, string $logText, string $breakLine) {
  5. return $logText . ' ' . $dateTime . $breakLine;
  6. });
  7. $log->error('Custom message, custom format');
  8. // Print log: var/log/error.log
  9. // Custom message, custom format [2018-06-16 04:06:25]