2017 © Pedro Peláez
 

library gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

image

graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  • Sunday, April 15, 2018
  • by lennart
  • Repository
  • 15 Watchers
  • 213 Stars
  • 3,943,199 Installations
  • PHP
  • 67 Dependents
  • 16 Suggesters
  • 62 Forks
  • 13 Open issues
  • 26 Versions
  • 9 % Grown

The README.md

gelf-php Latest Stable Version Total Downloads

Build Status Code Coverage Scrutinizer Quality Score, (*1)

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)., (*2)

It's a loosely based on the original Graylog2 gelf-php and mlehner's fork., (*3)

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., (*4)

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:, (*5)

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

After running an additional composer update everything should work as expected., (*6)

A note on PHP versions before 5.6

I tried to keep backwards compatibility alive as long as possible, but it 2021 it's not feasible anymore to deal with the pain of dependency management for PHP 5.3.3 - 5.5.latest. They are EOL for many years anyway., (*7)

If you are somehow stuck on <5.6, you can use gelf-php up to version 1.6.5., (*8)

I decided against a semver-compliant increase from 1.x to 2.x on purpose., (*9)

Usage

Add gelf-php to composer.json either by running composer require graylog2/gelf-php or by defining it manually:, (*10)

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

Reinstall dependencies: composer install, (*11)

Examples

For usage examples, go to /examples., (*12)

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., (*13)

How this applies in practice can be seen in the advanced-example., (*14)

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

Assuming you have a typical monolog config:, (*16)

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

You only need to properly define the symfony-service gelf-handler:, (*17)

services:
  monolog.gelf_handler:
    class: Monolog\Handler\GelfHandler
    arguments:
        - @gelf.publisher
        - 'warning' #monolog config is ignored with custom service level has to be redefined here (default : debug), you should probably use parameters eg: '%gelf_level%'

  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, (*18)

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:, (*19)

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., (*20)

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., (*21)

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 git@github.com: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

The Versions

15/04 2018

dev-master

9999999-dev

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

24/06 2017

1.5.5

1.5.5.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

20/01 2017

1.5.4

1.5.4.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

21/11 2016

1.5.3

1.5.3.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

21/11 2016

1.5.2

1.5.2.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

14/11 2016

1.5.1

1.5.1.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

02/06 2016

1.5.0

1.5.0.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

30/05 2016

1.4.2

1.4.2.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

22/10 2015

1.4.1

1.4.1.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

05/10 2015

1.4.0

1.4.0.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

15/06 2015

1.3.0

1.3.0.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

10/04 2015

1.2.3

1.2.3.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

21/03 2015

1.2.2

1.2.2.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

21/03 2015

dev-issues/25-docs

dev-issues/25-docs

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

17/03 2015

1.2.1

1.2.1.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

09/03 2015

1.2.0

1.2.0.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

26/02 2015

1.1.2

1.1.2.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

23/10 2014

1.1.1

1.1.1.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

16/10 2014

1.1.0

1.1.0.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

02/06 2014

1.0.4

1.0.4.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

by Benjamin Zikarsky

01/03 2014

1.0.3

1.0.3.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

by Benjamin Zikarsky

26/02 2014

1.0.2

1.0.2.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

by Benjamin Zikarsky

23/01 2014

1.0.1

1.0.1.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

19/12 2013

1.0.0

1.0.0.0

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Benjamin Zikarsky

19/12 2013

0.1.x-dev

0.1.9999999.9999999-dev http://github.com/Graylog2/gelf-php

PHP classes to send GELF (Graylog extended log format) messages

  Sources   Download

MIT

log logging

19/12 2013

0.1.0

0.1.0.0 http://github.com/Graylog2/gelf-php

PHP classes to send GELF (Graylog extended log format) messages

  Sources   Download

MIT

log logging