webarchitect609/log-tools 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webarchitect609/log-tools

Composer 安装命令:

composer require webarchitect609/log-tools

包简介

PSR-3 compatible logger tools

README 文档

README

Travis Build Status Latest version Downloads PHP version License More stuff from me

PSR-3 compatible logger tools

Features

  • Log any exception properly: with the stack trace, with all previous exceptions, etc
  • Daily logger: setup directory with log files with 'Y_m_d' timestamp as a filename

Installation

composer require webarchitect609/log-tools

Usage

LogExceptionTrait

Use \WebArch\LogTools\Traits\LogExceptionTrait instead of \Psr\Log\LoggerAwareTrait in the class you want to be able to log exceptions in more convenient way. Do not forget to implement \Psr\Log\LoggerAwareInterface.

When an exception or error occurs feel free to use logException() method to log it nice and easy. Exception chaining is enabled by default, but in case you don't need it you can use setChaining(false) method.

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LogLevel;
use WebArch\LogTools\Traits\LogExceptionTrait;

class FooService implements LoggerAwareInterface
{
    use LogExceptionTrait;

    public function __construct()
    {
        $this->setLogger(
            new Logger(
                'FooLogger',
                [new StreamHandler(sys_get_temp_dir() . '/foo-service.log')]
            )        
        );
    }

    public function bar()
    {
        try {

            throw new LogicException('Exception occurs in ' . __METHOD__);

        } catch (Throwable $exception) {

            /**
             * Exception will be logged with it's type, message, code, file, line and stack trace.
             */
            $this->logException($exception, LogLevel::CRITICAL, ['var1' => 'ABC']);
        }
    }

}

MonologLoggerFactory

Use \WebArch\LogTools\Factory\MonologLoggerFactory to simplify creating logs on daily basis.

use WebArch\LogTools\Enum\SystemStream;
use WebArch\LogTools\Factory\MonologLoggerFactory;

$debug = false;
$loggerFactory = new MonologLoggerFactory('/tmp/log/www', $debug);
$logger = $loggerFactory->createFileLogger('bar', 'foo/baz.log', SystemStream::STDERR);

/**
 * Creates `/tmp/log/www/foo/baz.log`
 * and outputs `[2019-02-15 12:42:59] bar.INFO: Hello, world! [] []` there
 * and to the STDERR. 
 */
$logger->info(
    'Hello, world!'
);

Known Issues

None so far.

Licence & Author Information

BSD-3-Clause

统计信息

  • 总下载量: 14.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固