承接 mougrim/php-logger 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mougrim/php-logger

最新稳定版本:v2.0.0

Composer 安装命令:

composer require mougrim/php-logger

包简介

Simple and fast php logging library

README 文档

README

If you want to maintain it, you can make a fork.

php-logger

This is a fork of Apache log4php logging library.

Main theme - light and fast library, with simple configuring.

If you want use classes without namespaces, see mougrim/php-logger-old-interface.

See changelog and upgrade instructions.

Latest Stable Version Latest Unstable Version License Build Status Test Coverage

Configuration

use Mougrim\Logger\Appender\AppenderStream;
use Mougrim\Logger\Layout\LayoutPattern;
use Mougrim\Logger\Layout\LayoutSimple;
use Mougrim\Logger\Logger;

Logger::configure([
    'policy' => [
        'ioError' => 'trigger_error', // ignore, trigger_warn, trigger_error, exception or exit
        'configurationError' => 'exception'
    ],
    'layouts' => [
        'simple' => [
            'class' => LayoutSimple::class,
        ],
        'pattern' => [
            'class' => LayoutPattern::class,
            'pattern' => '{date:Y/m/d} [{level}] {logger} {location:file:line, class.function} {mdc:key} {mdc} {ndc}: {message} {ex}',
        ],
    ],
    'appenders' => [
        'stream' => [
            'class' => AppenderStream::class,
            'stream' => 'php://stdout',
            // pass useLock and useLockShortMessage true for enable lock
            'useLock' => false,
            'useLockShortMessage' => false,
            'minLevel' => Logger::DEBUG,
            'maxLevel' => Logger::FATAL,
            'layout' => 'simple',
        ],
    ],
    'loggers' => [
        'logger' => [
            'appenders' => ['stream'],
            'addictive' => false,
            'minLevel' => Logger::TRACE,
            'maxLevel' => Logger::FATAL,
        ],
    ],
    'root' => [
        'appenders' => ['stream'],
    ]
]);

Logging

Logger::getLogger('logger')->trace("hello world");
Logger::getLogger('logger')->debug("hello world");
Logger::getLogger('logger')->info("hello world");
Logger::getLogger('logger')->warn("hello world");
Logger::getLogger('logger')->fatal("hello world");
Logger::getLogger('logger')->log(Logger::DEBUG, "hello world");

Mapped Diagnostic Context, mdc

LoggerMDC::put("request", $i++);
Logger::getLogger('accesslog')->info("new request");
Logger::getLogger('db')->info("execute sql");

# in some web log : cat log | grep 12412
accesslog [request=12412] new request
db [request=12412] execute sql

Timer

$logger = Logger::getLogger('db');
$timer = $logger->timer();
$pdo->exec('select * from foo');
$timer->info("sql executed at {time}"); // rendered at

Thanks

Thanks to mitallast for the development of the main part of this project.

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-25