amenadiel/slim-phpconsole 问题修复 & 功能扩展

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

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

amenadiel/slim-phpconsole

最新稳定版本:0.1.1

Composer 安装命令:

composer require amenadiel/slim-phpconsole

包简介

PHP-Console logging support for Slim Framework

README 文档

README

PHP-Console log writer for Slim Framework

Packagist

Use this custom log writer to output Slim Framework's log messages to your browser's console using PHP-Console.

Installation

Just add amenadiel/slim-phpconsole to your composer.json file in the require or require-dev sections:

{
    "require": {
        "amenadiel/slim-phpconsole":"~0.0.4"
    }
}

Usage

Instantiate the log writer. If you don't want to have the handler autostarted, pass false as a parameter, true is implied otherwise.

When the handler is started it will set itself as error and exception handler too, unless you set it otherwise.

    $logwriter = new \Amenadiel\SlimPHPConsole\PHPConsoleWriter(true);

    $app = new \Slim\Slim(array(
        'log.enabled' => true,
        'log.level' => \Slim\Log::DEBUG,
        'log.writer' => $logwriter
    ));

Starting from version 0.0.6 this adapter extends Slim\Middleware. Therefore, you can also use the add method of your app

    $app = new \Slim\Slim(array(
        'log.enabled' => true,
        'log.level' => \Slim\Log::DEBUG
    ));

    $app->add(new \Amenadiel\SlimPHPConsole\PHPConsoleWriter);

Both ways of setting PHP-Console as your logger are pretty much the same. Afterwards, you can send messages to your browser's console using $app->log's methods.

    $app->log->debug('Debug called!');
    $app->log->info('This is just info');
    $app->log->warning('Heads Up! This is a warning');

You can pass custom tags to PHPConsole by using this adapter's debug method which forwards its parameters to PHPConsole's debug method.

    $app->log->getWriter()->debug('This has a custom tag', 'custom.tag');

If you are using PHPConsole directly somewhere else in your app, remember not to start it twice, for it will throw an exception. Use its isStarted method to check if it's already started.

    $myHandler = \PhpConsole\Handler::getInstance();
    
    if (!$myHandler->isStarted()) {
        $myHandler->start(); // Only start it if it hasn't been started yet
    }

Optional Settings

You can use PHP-Console's configuration methods by getting a reference to the Handler instance or the Connector instance. For example:

   $logwriter = new \Amenadiel\SlimPHPConsole\PHPConsoleWriter(false);
   $handler = $logwriter->getHandler();
   $handler->setHandleErrors(false);  // disable errors handling, must be done before 'start' method
   $handler->start();

   $connector = $logwriter->getConnector();
   $connector->setPassword('macoy123'); //sets a very insecure passwd

统计信息

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

GitHub 信息

  • Stars: 12
  • Watchers: 13
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-03