0x20h / monoconf
此包已被弃用且不再维护。没有推荐替代包。
为 monolog 框架提供的类似 log4j 的日志配置
0.1.1
2013-06-06 20:25 UTC
Requires
- php: >=5.3.0
- monolog/monolog: >=1.5.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-07-02 06:35:37 UTC
README
Monoconf
为 monolog 日志框架提供的类似 log4j 的配置。
使用方法
- 创建配置 JSON 文件
{ "rules": { "*": { "error": { "handler": ["error-handler"] } }, "MyApp\\Controller*": { "debug": { "handler": ["debug-handler"], "processor": ["pid"] }, "error": { "handler": ["error-handler"] } } }, "handler": { "error-handler": { "type": "Monolog\\Handler\\StreamHandler", "args": [ "/my/app/error.log" ], "formatter": "line" }, "debug-handler": { "type": "Monolog\\Handler\\StreamHandler", "args": [ "/my/app/application.log" ], "formatter": "line" } }, "formatter": { "line": { "type": "Monolog\\Formatter\\LineFormatter", "args": [ "%datetime% %pid% %channel%@%level_name% %message% %context%\n" ] } }, "processor": { "pid": { "type": "Monolog\\Processor\\ProcessIdProcessor", "args": [ ] } } }
- 在您的应用程序中
require 'vendor/autoload.php'; use Monoconf\Monoconf; // initialize monoconf Monoconf::config(json_decode(file_get_contents('monoconf.json'), true));
namespace MyApp\Controller; class SomeController { protected $Log; public function __construct() { self::$Log = \Monoconf\Monoconf::getLogger(__CLASS__); } public function someAction() { self::$Log->debug(__METHOD__.' called'); } }
使用此设置,MyApp\Controller
命名空间中的每个类都将获得一个记录器,它将记录到 /my/app/error.log
的 debug
级别的消息,而其他每个类将获得一个记录器,它将记录到 /my/app/error.log
的 error
级别的消息。
测试
phpunit --bootstrap tests/bootstrap.php tests/