00f100/fcphp-log

该包最新版本(0.2.2)没有提供许可证信息。

fcphp应用的日志

安装: 66

依赖: 0

建议: 0

安全性: 0

星标: 1

关注者: 1

分支: 1

开放问题: 0

类型:

0.2.2 2019-03-05 05:01 UTC

This package is auto-updated.

Last update: 2024-09-18 05:25:41 UTC


README

用于操作FcPhp应用日志的包

Build Status codecov Total Downloads

如何安装

Composer

$ composer require 00f100/fcphp-log

或在composer.json中添加

{
    "require": {
        "00f100/fcphp-log": "*"
    }
}

如何使用

创建日志轻松!如果构造函数中$debug = false,则只需$log->error()$log->warning()即可...

<?php

use \FcPhp\Log\Log;

/*

    Method to return instance of Log
    
    @param string $directoryOutput Directory to write logs
    @param string|bool $dateFormat Format of date to print log. If `false` not print date
    @param string $extension Extension of file log
    @param bool $debug Enable debug mode
    @return FcPhp\Log\Interfaces\ILog

    Log::getInstance(string $directoryOutput, $dateFormat = 'Y-m-d H:i:s', string $extension = 'log', bool $debug = false) :ILog

*/

$log = Log::getInstance('var/log', 'Y-m-d H:i:s', 'log', true);

// To error logs
$log->error('message of error');
// Print log: var/log/error.log
// [2018-06-16 04:06:25] message of error

// To warning logs
$log->warning('message of warning');
// Print log: var/log/warning.log
// [2018-06-16 04:06:25] message of warning

// To debug
$log->debug('message debug');
// Print log: var/log/debug.log
// [2018-06-16 04:06:25] message debug

// To many types
$log->fooBar('message foo bar');
// Print log: var/log/fooBar.log
// [2018-06-16 04:06:25] message foo bar

自定义格式日志

<?php

use \FcPhp\Log\Log;

$log = Log::getInstance('var/log', 'Y-m-d H:i:s', 'log', true);

$log->customLog(function(string $dateTime, string $logText, string $breakLine) {
    return $logText . ' ' . $dateTime . $breakLine;
});

$log->error('Custom message, custom format');
// Print log: var/log/error.log
// Custom message, custom format [2018-06-16 04:06:25]