toeswade/log
最新稳定版本:v1.0
Composer 安装命令:
composer require toeswade/log
包简介
Small group of classes to build upon. Logs timestamps in code
关键字:
README 文档
README
- a simple logger class based on lydia/Clog
This class has no dependencies and can easily be implemented in any project. It saves timestamps in memory and renders a table at the end of the page.
Code Example
Create the $Clog object in the top of your script
$Clog = new Toeswade\Log\Clog();
Later use it in the classes you want to log . Note that the logger has to be accessible from your class
class Test { private $logger; public function __construct( \Toeswade\Log\Clog $Clog) { $this->logger = $Clog; } /* * Some method */ public function test() { $this->logger->stamp(__CLASS__, __METHOD__, 'Method starts'); // Some code $this->logger->stamp(__CLASS__, __METHOD__, 'Method ends'); } }
When you have logged all the timestamps of interest echo out the log table at the end of your script
echo $Clog->renderLog();
To see the class in action look at the example that comes with the package, starting in toeswade/log/webroot/index.php
Usage together with Anax-MVC
Installation
To start using toeswade/log together with Anax-MVC start with adding it to your composer.json "toeswade/log": "dev-master" and then run composer update to install the package.
Add the logger to DI and test it
Once you have downloaded that package add the logger to your DI-container
$this->setShared('logger', function () { $logger = new \Toeswade\Log\Clog(); return $logger; });
Then you can use it to set timestamps where ever you need in your code. For example in src/ThemeEngine/CThemeBasic
public function render() { $this->di->logger->stamp(__CLASS__, __METHOD__, 'render starts'); //... $this->di->logger->stamp(__CLASS__, __METHOD__, 'render ends'); }
To see your log just echo it at the end of your script
// Render the response using theme engine. $app->theme->render(); echo $app->logger->renderLog();
Clean out the example code
Note that the code in webroot and src/Test isn't necessary for the package to work.
Motivation
This class is part of a task in the course phpmvc at BTH, Sweden.
Tests
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-01