Giter Club home page Giter Club logo

elastica-logzio's Introduction

PHP Logz.io Logger

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.