$logger =new\Monolog\Logger("tars_logger");//remote log$tarsHandler =new\Tars\log\handler\TarsHandler($config);//local log 这里可以根据业务需要添加其他handler,比如StreamHandler、ElasticSearchHandler 等$streamHandler =new\Monolog\Handler\StreamHandler(ENVConf::$logPath."/".__CLASS__.".log");$logger->pushHandler($tarsHandler);$logger->pushHandler($streamHandler);$array = ["key1"=>"value1","key2"=>"value2","key3"=>"value3"];$logger->debug("add a debug message", $array);$logger->info("add a info message", $array);$logger->notice("add a notice message", $array);$logger->warning("add a warning message", $array);$logger->error("add a error message", $array);$logger->critical("add a critical message", $array);$logger->emergency("add a emergency message", $array);
$logger =new\Monolog\Logger("elk_logger");$client =new\Elastica\Client(['host'=>'127.0.0.1','port'=>9200]);$elkHanlder =newMonolog\Handler\ElasticSearchHandler($client, ['index'=>'monolog_index_test','type'=>'record']);$logger->pushHandler($elkHanlder);$logger->error("this is a test msg from monolog");