Git Product home page Git Product logo

gelf-php's Introduction

gelf-php Latest Stable Version Total Downloads

Build Status Code Coverage Scrutinizer Quality Score

A php implementation to send log-files to a gelf compatible backend like Graylog2. This library conforms to the PSR standards in regards to structure (4), coding-style (1, 2) and logging (3).

It's a loosely based on the original Graylog2 gelf-php and mlehner's fork.

Stable release and deprecation of the original graylog2/gelf-php

This implementation became the official PHP GELF library on 2013-12-19 and is now released as graylog2/gelf-php. The old library became deprecated at the same time and it's recommended to upgrade.

Since the deprecated library never got a stable release, we decided keep it available as v0.1. This means: If you have a project based on the deprecated library but no time to upgrade to version 1.0, we recommend to change your composer.json as following:

    "require": {
       // ...
       "graylog2/gelf-php": "0.1.*"
       // ...
    }

After running an additional composer update everything should work as expected.

Usage

Recommended installation via composer:

Add gelf-php to composer.json either by running composer require graylog2/gelf-php or by defining it manually:

"require": {
   // ...
   "graylog2/gelf-php": "~1.5"
   // ...
}

Reinstall dependencies: composer install

Examples

For usage examples, go to /examples.

Muting connection and transport errors

Oftentimes projects run into the situation where they don't want to raise exceptions for logging-errors. Since the standard transports like Udp, Tcp and Http can be kind of noise for fwrite/fopen errors, gelf-php provides a IgnoreErrorTransportWrapper. This class can decorate any AbstractTransport and will mute all exceptions.

How this applies in practice can be seen in the advanced-example.

If you use gelf-php in conjunction with monolog/symfony, the following snippet should help you with properly setting up your logging backend.

Assumung you have a typical monolog config:

monolog:
  handlers:
    graylog:
      type: service
      id: monolog.gelf_handler
      level: debug

You only need to properly define the symfony-service gelf-handler:

services:
  monolog.gelf_handler:
    class: Monolog\Handler\GelfHandler
    arguments: [@gelf.publisher]
    
  gelf.publisher:
    class: Gelf\Publisher
    arguments: [@gelf.ignore_error_transport]
    
  gelf.ignore_error_transport:
    class: Gelf\Transport\IgnoreErrorTransportWrapper
    arguments: [@gelf.transport]
    
  gelf.transport:
    class: Gelf\Transport\UdpTransport # or Tcp, Amp, Http,...
    arguments: [] # ... whatever is required

HHVM

While HHVM is supported/tested, there are some restrictions to look out for:

  • Stream-context support is very limited (as of 2014) - especially regarding SSL - many use-cases might not work as expected (or not at all...)
  • fwrite does behave a little different

The failing unit-tests are skipped by default when running on HHVM. They are also all annotated with @group hhvm-failures. You can force to run those failures by setting FORCE_HHVM_TESTS=1 in the environment. Therefore you can specifically check the state of HHVM failures by running:

FORCE_HHVM_TESTS=1 hhvm vendor/bin/phpunit --group hhvm-failures

License

The library is licensed under the MIT license. For details check out the LICENSE file.

Development & Contributing

You are welcome to modify, extend and bugfix all you like. :-) If you have any questions/proposals/etc. you can contact me on Twitter (@bzikarsky) or message me on freenode#graylog2.

Tools

  1. composer, preferably a system-wide installation as composer
  2. PHPUnit
  3. Optional: PHP_CodeSniffer for PSR-X-compatibility checks

Steps

  1. Clone repository and cd into it: git clone [email protected]:bzikarsky/gelf-php && cd gelf-php
  2. Install dependencies: composer install
  3. Run unit-tests: vendor/bin/phpunit
  4. Check PSR compatibility: vendor/bin/phpcs --standard=PSR2 src tests examples

gelf-php's People

Contributors

afoeder avatar betweenbrain avatar bzikarsky avatar carusogabriel avatar chrisminett avatar chrisnew avatar cosmologist avatar dbu avatar evaldaskocys avatar gummibeer avatar h4cc avatar jacobkiers avatar jeroendedauw avatar matthi4s avatar mrjgreen avatar olegpro avatar pascalwild avatar seldaek avatar steffkes avatar tobion avatar toubsen avatar

Watchers

 avatar

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.