码迷,mamicode.com
首页 > Web开发 > 详细

monolog php

时间:2016-08-22 17:56:46      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

include_once IA_ROOT . ‘/lib/log/PDOHandler.php‘;

use Monolog\Logger;
 

$loger = new Logger(‘name‘);

$pdo = new PDO(‘mysql:host=xxxxx;dbname=weishop;charset=utf8‘, ‘username‘, ‘password‘);
$dd = new PDOHandler($pdo);
$loger->pushHandler($dd);
$loger->addInfo(‘My logger is now ready‘);
$loger->debug("debug info2222");
class PDOHandler extends AbstractProcessingHandler { private $initialized = false; private $pdo; private $statement; public function __construct(PDO $pdo, $level = Logger::DEBUG, $bubble = true) { $this->pdo = $pdo; parent::__construct($level, $bubble); } protected function write(array $record) { if (!$this->initialized) { $this->initialize(); } $this->statement->execute(array( ‘channel‘ => $record[‘channel‘], ‘level‘ => $record[‘level‘], ‘message‘ => $record[‘formatted‘], ‘time‘ => $record[‘datetime‘]->format(‘U‘), )); } private function initialize() { $this->pdo->exec( ‘CREATE TABLE IF NOT EXISTS monolog ‘ .‘(channel VARCHAR(255), level INTEGER, message LONGTEXT, time INTEGER UNSIGNED)‘ ); $this->statement = $this->pdo->prepare( ‘INSERT INTO monolog (channel, level, message, time) VALUES (:channel, :level, :message, :time)‘ ); $this->initialized = true; } }

monolog php

标签:

原文地址:http://www.cnblogs.com/anjuncc/p/5796292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!