PHPackages                             giacomofurlan/php-graylog-gelf - 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. giacomofurlan/php-graylog-gelf

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

giacomofurlan/php-graylog-gelf
==============================

A PHP PSR-3 compliant logger to send data to graylog2 (GELF format)

1.1.2(7y ago)07.9kMITPHPPHP ^7.1

Since Aug 29Pushed 7y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

PHP GELF logger
===============

[](#php-gelf-logger)

This library aims to help the developer with both a PSR-3 compliant and a custom (extended) logger to send data to Graylog 2 via the Graylog Extended Log Format.

Class information
-----------------

[](#class-information)

### `GiacomoFurlan\Graylog\GELFLogger`

[](#giacomofurlangrayloggelflogger)

It implements the Psr\\Log\\LoggerInterface interface, so use it as a standard logger.

It can set the short message, the context and the log level.

### `GiacomoFurlan\Graylog\ExtendedGELFLogger`

[](#giacomofurlangraylogextendedgelflogger)

It extends the previous class, but add `gelf*` functions to send more complex information.

It also allows the logs to be enqueued, rather than being sent immediately.

- `gelfLog`
- `gelfAlert`
- `gelfCritical`
- `gelfDebug`
- `gelfEmergency`
- `gelfError`
- `gelfInfo`
- `gelfNotice`
- `gelfWarning`
- `flush`

These function accept a GELF object and the possibility to flush the messages instantly (default true).

The `flush` function flushes eventual messages previously enqueued.

### `GiacomoFurlan\Graylog\GELF`

[](#giacomofurlangrayloggelf)

A data-transfer object used by `ExtendedGELFLogger`. It allows to set the short and full messages, to overwrite the `host` information and to add variables to the context.

### `GiacomoFurlan\Graylog\UDPWriter`

[](#giacomofurlangraylogudpwriter)

UDP implementation of the `WriterInterface` used to instantiate the loggers.

If there are enqueued messages (writing with `flush` set to `false`, changeable using the extended logger), it will try to run `flush` when destroyed.

### `GiacomoFurlan\Graylog\TCPWriter`

[](#giacomofurlangraylogtcpwriter)

UDP implementation of the `WriterInterface` used to instantiate the loggers.

If there are enqueued messages (writing with `flush` set to `false`, changeable using the extended logger), it will try to run `flush` when destroyed.

### `GiacomoFurlan\Graylog\GELFException`

[](#giacomofurlangrayloggelfexception)

It can be thrown trying to send the information.

- Code `GELFException::CODE_MISSING_HOST`: the host is's not set or empty
- Code `GELFException::CODE_CANT_SEND_MESSAGE`: an error occurred trying to send the packet

More information may be gathered reading the exception's message.

Usage example
-------------

[](#usage-example)

```

use GiacomoFurlan\Graylog\ExtendedGELFLogger;
use GiacomoFurlan\Graylog\GELF;
use GiacomoFurlan\Graylog\GELFException;
use GiacomoFurlan\Graylog\GELFLogger;
use GiacomoFurlan\Graylog\UDPWriter;
use Psr\Log\LogLevel;

// ...

$address = 'ip.or.dns.of.graylog.server';
$port = 12201; // or whatever port is configured in Graylog 2
$hostId = 'MyHost'; // host identifier

// Instantiate the writer
$writer = new UDPWriter($address, $port);
// Instantiate the logger (use one or the other... or both)
$simpleLogger = new GELFLogger($writer, $hostId);
$extendedLogger = new ExtendedGELFLogger($writer, $hostId);

// ...

// GELFLogger usage example
try {
  // ...
} catch (\Throwable $exception) {
    $simpleLogger->log(LogLevel::ERROR, $exception->getMessage(), ['code' => $exception->getCode()]);
    // or
    $simpleLogger->error($exception->getMessage(), ['code' => $exception->getCode()]);
}

// ExtendedGELFLogger usage example
try {
    // ...
} catch (\Throwable $exception) {
    $message = new GELF($exception->getMessage(), ['code' => $exception->getCode()]);

    $message->setHost('Overwritten host');
    $message->setFullMessage($exception->getTraceAsString());
    $message->setContextEntryset('fileName', $exception->getFile());
    $message->setContextEntryset('fileLine', $exception->getLine());

    $extendedLogger->gelfError($message);
}

```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity60

Established project with proven stability

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 ~54 days

Total

4

Last Release

2647d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5558fe66fdc65b41b2d2c9692ad40cccf80176db8de20d9c0926b3248e1b11fa?d=identicon)[giacomofurlan](/maintainers/giacomofurlan)

---

Tags

psrloggergraylog2gelfudp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[hedii/laravel-gelf-logger

A Laravel package to send logs to a gelf compatible backend like graylog

1333.4M10](/packages/hedii-laravel-gelf-logger)[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3451.5M24](/packages/analog-analog)[apix/log

Minimalist, thin and fast PSR-3 compliant (multi-bucket) logger.

511.0M18](/packages/apix-log)

PHPackages © 2026

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