PHPackages                             graylog2/gelf-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. graylog2/gelf-php

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

graylog2/gelf-php
=================

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

2.0.2(1y ago)41838.2M—4.5%88[8 issues](https://github.com/bzikarsky/gelf-php/issues)[10 PRs](https://github.com/bzikarsky/gelf-php/pulls)20MITPHPPHP &gt;=8.0CI failing

Since Dec 19Pushed 1y ago14 watchersCompare

[ Source](https://github.com/bzikarsky/gelf-php)[ Packagist](https://packagist.org/packages/graylog2/gelf-php)[ RSS](/packages/graylog2-gelf-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (43)Used By (20)

gelf-php [![Latest Stable Version](https://camo.githubusercontent.com/df2d23418a03f4ae8679180f405530c3a22d012f2a7752e436221792ee32f120/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677261796c6f67322f67656c662d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graylog2/gelf-php) [![Total Downloads](https://camo.githubusercontent.com/7a2798916fc660e6fffb2d5248df05da49d6a14ea96f38599dc55218233567b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677261796c6f67322f67656c662d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graylog2/gelf-php)
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#gelf-php--)

[![Build Status](https://camo.githubusercontent.com/de5f0b3e1adeaa111b0ba5d976c759fa4c06af7907a7b1599d8c27a26fc45906/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f627a696b6172736b792f67656c662d7068702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/bzikarsky/gelf-php)[![Code Coverage](https://camo.githubusercontent.com/c24981a3267d31eeaa9147adca364ffee49ca112cd76d11515dbdceb366d8d4d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f627a696b6172736b792f67656c662d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bzikarsky/gelf-php/)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/5e294d3f2407d2ba2f157addffd74b913d256a7a2c82f6a6ef8cdd7f27152e21/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f627a696b6172736b792f67656c662d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bzikarsky/gelf-php/)

A php implementation to send log-files to a gelf compatible backend like [Graylog2](http://graylog2.org/). This library conforms to the PSR standards in regards to structure ([4](http://www.php-fig.org/psr/psr-4/)), coding-style ([1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md), [2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)) and logging ([3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)).

It's a loosely based on the original [Graylog2 gelf-php](https://github.com/Graylog2/gelf-php)and [mlehner's fork](https://github.com/mlehner/gelf-php).

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

[](#stable-release-and-deprecation-of-the-original-graylog2gelf-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.

A note on PHP versions before 5.6
---------------------------------

[](#a-note-on-php-versions-before-56)

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.

**If you are somehow stuck on &lt;5.6, you can use gelf-php up to version 1.6.5**.

I decided against a semver-compliant increase from 1.x to 2.x on purpose.

Usage
-----

[](#usage)

### Recommended installation via composer:

[](#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

[](#examples)

For usage examples, go to [/examples](https://github.com/bzikarsky/gelf-php/tree/master/examples).

### Muting connection and transport errors

[](#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](https://github.com/bzikarsky/gelf-php/blob/master/examples/advanced.php#L18-L20).

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

Assuming 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
        - '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
----

[](#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
-------

[](#license)

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

Development &amp; Contributing
------------------------------

[](#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](https://twitter.com/bzikarsky)) or message me on freenode#graylog2.

### Tools

[](#tools)

1. [composer](http://getcomposer.org), preferably a system-wide installation as `composer`
2. [PHPUnit](http://phpunit.de/manual/current/en/installation.html)
3. Optional: [PHP\_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for PSR-X-compatibility checks

### Steps

[](#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`

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance41

Moderate activity, may be stable

Popularity70

Solid adoption and visibility

Community50

Growing community involvement

Maturity80

Battle-tested with a long release history

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~112 days

Recently: every ~255 days

Total

37

Last Release

483d ago

Major Versions

0.1.x-dev → 1.0.02013-12-19

1.7.1 → 2.0.x-dev2022-04-05

PHP version history (5 changes)1.0.0PHP ~5.3

1.1.2PHP &gt;=5.3

1.2.1PHP &gt;=5.3.9

1.7.0PHP &gt;=5.6

2.0.x-devPHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd2e7840c7ce6628cd979c754dc36ec2cbc2c4fa6757d5cab062d65ce086990a?d=identicon)[lennart](/maintainers/lennart)

![](https://www.gravatar.com/avatar/20c8f3d1937ed09e48f4f3a689556f9033e43a267f592901c4330f6afe159c85?d=identicon)[bzikarsky](/maintainers/bzikarsky)

---

Top Contributors

[![bzikarsky](https://avatars.githubusercontent.com/u/225374?v=4)](https://github.com/bzikarsky "bzikarsky (33 commits)")[![JustinDugas](https://avatars.githubusercontent.com/u/27973284?v=4)](https://github.com/JustinDugas "JustinDugas (10 commits)")[![steffkes](https://avatars.githubusercontent.com/u/325361?v=4)](https://github.com/steffkes "steffkes (5 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (4 commits)")[![Seldaek](https://avatars.githubusercontent.com/u/183678?v=4)](https://github.com/Seldaek "Seldaek (3 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (3 commits)")[![evaldaskocys](https://avatars.githubusercontent.com/u/8693654?v=4)](https://github.com/evaldaskocys "evaldaskocys (3 commits)")[![Ocramius](https://avatars.githubusercontent.com/u/154256?v=4)](https://github.com/Ocramius "Ocramius (3 commits)")[![toubsen](https://avatars.githubusercontent.com/u/553786?v=4)](https://github.com/toubsen "toubsen (2 commits)")[![cseufert](https://avatars.githubusercontent.com/u/1734519?v=4)](https://github.com/cseufert "cseufert (2 commits)")[![versh23](https://avatars.githubusercontent.com/u/1758392?v=4)](https://github.com/versh23 "versh23 (2 commits)")[![xel1045](https://avatars.githubusercontent.com/u/1497697?v=4)](https://github.com/xel1045 "xel1045 (2 commits)")[![dbu](https://avatars.githubusercontent.com/u/76576?v=4)](https://github.com/dbu "dbu (2 commits)")[![matthi4s](https://avatars.githubusercontent.com/u/8943286?v=4)](https://github.com/matthi4s "matthi4s (2 commits)")[![pascalwild](https://avatars.githubusercontent.com/u/14974414?v=4)](https://github.com/pascalwild "pascalwild (2 commits)")[![mrjgreen](https://avatars.githubusercontent.com/u/2183391?v=4)](https://github.com/mrjgreen "mrjgreen (2 commits)")[![Chris8934](https://avatars.githubusercontent.com/u/44963939?v=4)](https://github.com/Chris8934 "Chris8934 (2 commits)")[![jfredon](https://avatars.githubusercontent.com/u/13495514?v=4)](https://github.com/jfredon "jfredon (1 commits)")[![chrisnew](https://avatars.githubusercontent.com/u/994286?v=4)](https://github.com/chrisnew "chrisnew (1 commits)")[![Cosmologist](https://avatars.githubusercontent.com/u/966525?v=4)](https://github.com/Cosmologist "Cosmologist (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/graylog2-gelf-php/health.svg)

```
[![Health](https://phpackages.com/badges/graylog2-gelf-php/health.svg)](https://phpackages.com/packages/graylog2-gelf-php)
```

###  Alternatives

[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k227.1M273](/packages/sentry-sentry)[rollbar/rollbar

Monitors errors and exceptions and reports them to Rollbar

33723.7M82](/packages/rollbar-rollbar)[illuminate/log

The Illuminate Log package.

6224.3M518](/packages/illuminate-log)[open-telemetry/api

API for OpenTelemetry PHP.

1933.0M214](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2322.9M248](/packages/open-telemetry-sdk)[pagemachine/typo3-formlog

Form log for TYPO3

23225.3k6](/packages/pagemachine-typo3-formlog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
