Skip to content

Instantly share code, notes, and snippets.

@582033
Last active August 30, 2017 01:57
Show Gist options
  • Save 582033/8d18a63b445c7a97e6bc4ac54dd8b26e to your computer and use it in GitHub Desktop.
Save 582033/8d18a63b445c7a97e6bc4ac54dd8b26e to your computer and use it in GitHub Desktop.
<?php
require_once __DIR__ . '/vendor/autoload.php';
//namespace libs;
use Monolog\Logger;
use Monolog\Handler\RedisHandler;
use Monolog\Formatter\LogstashFormatter;
use Predis\Client;
class log {
public $logger;
public function __construct($channel, $type){
$this->redisConf = array(
'host' => '10.15.206.221',
'port' => '6379',
'password' => 'pwd',
);
$this->logConf = array(
'redisKey' => 'logstash',
#channel用于区分项目名称
'channel' => 'upload_youku',
#
'type' => $type,
);
$this->_init();
}
private function _init(){
$this->logger = new logger($this->logConf['channel']);
//创建redis handler
$redisHandler = new RedisHandler(new Client($this->redisConf), $this->logConf['redisKey']);
//设置handler格式
$formatter = new LogstashFormatter($this->logConf['type']);
$redisHandler->setFormatter($formatter);
//装载handler
$this->logger->pushHandler($redisHandler);
}
}
$log = new log('foo', 'bar');
$log->logger->info('我是测试消息', array('extensionMsg' => '我是任意的扩展日志信息,可以是string'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment