lordoffreak/elastica-logzio 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lordoffreak/elastica-logzio

Composer 安装命令:

composer require lordoffreak/elastica-logzio

包简介

PHP client to save realtime logs to Logz.io

README 文档

README

PHP library to send realtime logs to Logz.io, an ELK as a service.

Installing

Install with composer:

$ composer require lordoffreak/elastica-logzio

Usage

First of all, you need an account on Logz.io. Then, go to you profile settings and get your api key (token).

Configure

To configure the library, you just need to get an instance of LogzIO\Transport\LogzIOGuzzle, set the token and the the type. You need to do it once per Transport. After that create an instance of LogzIO\LogzIOElasticaClient and use it as a normal Elastica\Client client.

<?php
use LogzIO\LogzIOElasticaClient;
use LogzIO\Transport\LogzIOGuzzle;

$config = [];
$config['transport'] = new LogzIOGuzzle();
$config['transport']->setToken('YOUR_API_KEY');
$config['transport']->setType('record');

$client = new LogzIOElasticaClient($config);

Sending logs

To send a log, you need to get an instance of LogzIO\LogzIOElasticaClient and use it as a normal Elastica\Client client:

<?php
use LogzIO\LogzIOElasticaClient;
use LogzIO\Transport\LogzIOGuzzle;

$config = [];
$config['transport'] = new LogzIOGuzzle();
$config['transport']->setToken('YOUR_API_KEY');
$config['transport']->setType('record');

$client = new LogzIOElasticaClient($config);
$data = [
    'name' => 'Alejandro',
    'surname' => 'Tabares',
];

// First parameter is the id of document.
$documents = [
    new \Elastica\Document($id, $data)
];

$resp = $client->addDocuments([$documents);

Usage with Monolog

As described in https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/ElasticSearchHandler.php#L23 just:

<?php
use LogzIO\LogzIOElasticaClient;
use LogzIO\Transport\LogzIOGuzzle;

// Your type.
$type = 'record';
$config = [];
$config['transport'] = new LogzIOGuzzle();
$config['transport']->setToken('YOUR_API_KEY');
$config['transport']->setType($type);

$client = new LogzIOElasticaClient($config);

$options = array(
    'index' => 'YOUR_INDEX_NAME',
    'type' => $type,
);

$handler = new ElasticSearchHandler($client, $options);
$log = new Logger('application');
$log->pushHandler($handler);

Contributing

To contribute, create a fork, make your changes, make tests, test and create a PR.

License

This library is licenced under MIT.

统计信息

  • 总下载量: 3.6k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固