jlaso / simple-logger
为您的PHP应用程序提供一个简单的日志记录器
1.0.3
2016-11-10 23:05 UTC
Requires
- php: >=5.4
- symfony/yaml: *
Requires (Dev)
- mockery/mockery: 0.9.1
- phpunit/phpunit: ~4.0
- symfony/console: 2.4.1
This package is auto-updated.
Last update: 2024-09-15 11:01:03 UTC
README
simple-logger
一个简单的日志系统
安装
您只需在项目中要求此包 composer require jlaso/simple-logger
配置(可选)
为了让库知道可以放置其数据库文件和其他相关设置,您可以将分发文件 config-simple-logger.yml.dist
复制到项目的根目录下,命名为 config-simple-logger.yml
此文件包含
# vendor/jlaso/simple-logger/config-simple-logger.yml.dist
logger:
path: "%project_dir%/cache/logger-%date%.log"
levels: error,info,debug
date_format: "Y-m-d"
命令
为了检查日志文件,您可以使用 src/console log:filter [--with=word1,word2,...] [--levels=error,info] [--date-from="2016-01-01 00:00:00"]
运行示例
转到终端并启动演示示例 php demo.php
<?php
error_reporting(E_ALL & !E_WARNING);
require_once __DIR__.'/vendor/autoload.php';
use JLaso\SimpleLogger\PlainFileLogger as Logger;
$start = microtime(true);
Logger::info("This is only the start of the program");
Logger::debug(array(
'title' => 'This is the title',
'data' => 'more data',
));
$a = 1234/ $b;
set_error_handler('error_handler');
function error_handler($e)
{
Logger::error($e);
}
Logger::info('Just finishing the execution of the program in '.intval((microtime(true)-$start)*1000).' msec !');
在您的应用程序中实现过滤器命令
您可以看到如何实现它的一个示例(https://github.com/jlaso/simple-stats-demo/tree/master/app)[https://github.com/jlaso/simple-stats-demo/tree/master/app])
<?php
namespace App\Command;
use JLaso\SimpleLogger\Command\FilterCommand;
class FilterLogCommand extends FilterCommand
{
}
添加到app/console
#!/usr/bin/env php
<?php
namespace JLaso\SimpleStats;
require_once __DIR__ . '/../vendor/autoload.php';
use App\Command\FilterLogCommand; <======
use App\Command\PostDeployCommand;
use Symfony\Component\Console\Application;
$application = new Application();
$application->addCommands(
array(
new PostDeployCommand(),
new FilterLogCommand(), <======
)
);
$application->run();