PHPackages                             khalyomede/syslog - 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. khalyomede/syslog

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

khalyomede/syslog
=================

Log into your Syslog destination

v1.0.0(8y ago)012MITPHPPHP &gt;=7.0.0

Since Mar 31Pushed 8y ago1 watchersCompare

[ Source](https://github.com/khalyomede/syslog)[ Packagist](https://packagist.org/packages/khalyomede/syslog)[ RSS](/packages/khalyomede-syslog/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Syslog
======

[](#syslog)

[![PHP from Packagist](https://camo.githubusercontent.com/8e8405bd844fa175b4c6a8395356710dc7544f4098c7e3a33caf2837acdc8af1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b68616c796f6d6564652f7379736c6f672e737667)](https://camo.githubusercontent.com/8e8405bd844fa175b4c6a8395356710dc7544f4098c7e3a33caf2837acdc8af1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b68616c796f6d6564652f7379736c6f672e737667)[![Packagist](https://camo.githubusercontent.com/21146a5f425a77195d47b198268230b71dcdb678aef54076422646bd12264105/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68616c796f6d6564652f7379736c6f672e737667)](https://camo.githubusercontent.com/21146a5f425a77195d47b198268230b71dcdb678aef54076422646bd12264105/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68616c796f6d6564652f7379736c6f672e737667)[![Packagist](https://camo.githubusercontent.com/833e378d0f4b5b37c172e0931d5f94dd0eb12f210834e3e30a4d9f326fb5a5c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68616c796f6d6564652f7379736c6f672e737667)](https://camo.githubusercontent.com/833e378d0f4b5b37c172e0931d5f94dd0eb12f210834e3e30a4d9f326fb5a5c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68616c796f6d6564652f7379736c6f672e737667)

Log into your Syslog destination.

```
$log->host('some.vendor.com')
  ->port(92883)
  ->facility(22)
  ->source('my.company.io')
  ->device('website')
  ->processus('price-index');

$log->debug('page loaded in 3.840 s');
```

Summary
-------

[](#summary)

- [Prerequistes](#prerequistes)
- [Installation](#installation)
- [Examples of uses](#examples-of-uses)
- [Methods definitions](#methods-definitions)
- [Prototype ready](#prototype-ready)

Prerequistes
------------

[](#prerequistes)

- PHP version &gt;= 7.0.0
- Socket extension enabled (`php_sockets.dll` on windows or `php_sockets.so` on Linux distributions)
- A log server that accepts UDP packet messages (as this library send the log through UDP)

Installation
------------

[](#installation)

In your project folder:

```
composer require khalyomede/syslog:1.*
```

Examples of uses
----------------

[](#examples-of-uses)

All the examples can be found in the `/example` folder.

- [Example 1: logging into your log destination](#example-1-logging-into-your-log-destination)
- [Example 2: templatize your message for logging](#example-2-templatize-your-message-for-logging)
- [Example 3: use a generic method for logging](#example-3-use-a-generic-method-for-logging)
- [Example 4: templatize when using the generic logging](#example-4-templatize-when-using-the-generic-logging)
- [Example 5: force the date before logging](#example-5-force-the-date-before-loggin)
- [Example 6: specify an indentifier for your next logs](#example-6-specify-an-identifier-for-your-next-logs)

### Example 1: logging into your log destination

[](#example-1-logging-into-your-log-destination)

```
use Khalyomede\Syslog;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home');

$log->debug("user created in 5ms");
```

### Example 2: templatize your message for logging

[](#example-2-templatize-your-message-for-logging)

```
use Khalyomede\Syslog;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home');

$message = "user {username} created successfuly";

$log->info($message, ['username' => 'johndoe']);
```

### Example 3: use a generic method for logging

[](#example-3-use-a-generic-method-for-logging)

```
use Khalyomede\Syslog;
use Psr\Log\LogLevel;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home');

$log->log(LogLevel::ERROR, "the user could not be created because: this username already exists");
```

If you do not want to pass through the class constants of `LogLevel`, you can provide a string instead:

```
$log->log('error' 'the user could not be created because: this username already exists');
```

Beware that the informational severity string equivalent is `info`.

### Example 4: templatize when using the generic logging

[](#example-4-templatize-when-using-the-generic-logging)

```
use Khalyomede\Syslog;
use Psr\Log\LogLevel;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home');

$message = "user {username} created successfuly";

$log->log(LogLevel::ERROR, $message, ['username' => 'johndoe']);
```

### Example 5: force the date before logging

[](#example-5-force-the-date-before-logging)

```
use Khalyomede\Syslog;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home')
  ->date(new DateTime('2017-11-29 04:34:09', new DateTimeZone('Europe/Paris')));

$log->emergency('detected forbidden access to database');
```

### Example 6: specify an indentifier for your next logs

[](#example-6-specify-an-indentifier-for-your-next-logs)

```
use Khalyomede\Syslog;

$log = new Syslog;

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home')
  ->identifier('AZXT6');

$log->debug("database optimized in 33.09 s.");
```

The identifier will stick to your next logs. If you would like to clear it at a point, you can use:

```
$log->deleteIdentifier();
```

It returns an instance of `Khalyomede\Syslog` so you can chain it with any other method.

Methods definitions
-------------------

[](#methods-definitions)

- [`alert`](#alert)
- [`critical`](#critical)
- [`date`](#date)
- [`debug`](#debug)
- [`deleteIdentifier`](#deleteidentifier)
- [`device`](#device)
- [`emergency`](#emergency)
- [`error`](#error)
- [`facility`](#facility)
- [`host`](#host)
- [`identifier`](#identifier)
- [`info`](#info)
- [`log`](#log)
- [`notice`](#notice)
- [`port`](#port)
- [`processus`](#processus)
- [`source`](#source)
- [`warning`](#warning)

### alert

[](#alert)

Sends a message to the log destination with an alert severity.

```
public function alert(string $message, array $context = []): Syslog
```

**Note**

The keys of the context should respect the following format: lower case, numbers, with underscores and periods only.

**Exception**

`InvalidArgumentException`:

- If the message is empty
- If the context does not contains an array of key-pairs values
- If one of the context keys is not properly formated

`LogicException`:

- If one of the following properties are not filled: host, post, source, device, processus

`RuntimeException`:

- If the socket creation failed
- If the message could not be sent through the socket connection

### critical

[](#critical)

Sends a message to the log destination with a critical severity.

```
public function critical(string $message, array $context = []): Syslog
```

**Note**

The keys of the context should respect the following format: lower case, numbers, with underscores and periods only.

**Exception**

`InvalidArgumentException`:

- If the message is empty
- If the context does not contains an array of key-pairs values
- If one of the context keys is not properly formated

`LogicException`:

- If one of the following properties are not filled: host, post, source, device, processus

`RuntimeException`:

- If the socket creation failed
- If the message could not be sent through the socket connection

### date

[](#date)

Force the log to be timestamped to a specific date.

```
public function date(DateTime $date): Syslog
```

**Note**

If you do not call this method at each log call, the date will be set to the time at which you call the sysloger.

### debug

[](#debug)

Sends a message to the log destination with a debug severity.

```
public function debug(string $message, array $context = []): Syslog
```

**Note**

The keys of the context should respect the following format: lower case, numbers, with underscores and periods only.

**Exception**

`InvalidArgumentException`:

- If the message is empty
- If the context does not contains an array of key-pairs values
- If one of the context keys is not properly formated

`LogicException`:

- If one of the following properties are not filled: host, post, source, device, processus

`RuntimeException`:

- If the socket creation failed
- If the message could not be sent through the socket connection

### deleteIdentifier

[](#deleteidentifier)

Reset the identifier to its empty value.

```
public function deleteIdentifier(): Syslog
```

### device

[](#device)

Set the name of the device that is sending the log. For more information, see the definition of this attribute on the [Syslog RFC5424 documentation](https://tools.ietf.org/html/rfc5424#section-6.2.5).

```
public function device(string $device): Syslog
```

### emergency

[](#emergency)

Sends a message to the log destination with an emergency severity.

```
public function emergency(string $message, array $context = []): Syslog
```

**Note**

The keys of the context should respect the following format: lower case, numbers, with underscores and periods only.

**Exception**

`InvalidArgumentException`:

- If the message is empty
- If the context does not contains an array of key-pairs values
- If one of the context keys is not properly formated

`LogicException`:

- If one of the following properties are not filled: host, post, source, device, processus

`RuntimeException`:

- If the socket creation failed
- If the message could not be sent through the socket connection

### error

[](#error)

Sends a message to the log destination with an error severity.

```
public function error(string $message, array $context = []): Syslog
```

**Note**

The keys of the context should respect the following format: lower case, numbers, with underscores and periods only.

**Exception**

`InvalidArgumentException`:

- If the message is empty
- If the context does not contains an array of key-pairs values
- If one of the context keys is not properly formated

`LogicException`:

- If one of the following properties are not filled: host, post, source, device, processus

`RuntimeException`:

- If the socket creation failed
- If the message could not be sent through the socket connection

### facility

[](#facility)

Set the target plateform. For more information, see the definition of this attribute on the [Syslog RFC5424 documentation](https://tools.ietf.org/html/rfc5424#section-6.2.1).

```
public function facility(int $facility): Syslog
```

### host

[](#host)

Set the target log destination host.

```
public function host(string $host): Syslog
```

**Note**

The value should be an IP or a valid domain.

### identifier

[](#identifier)

Set an optional identifier to group your logs.

```
public function source(string $source): Syslog
```

### info

[](#info)

Sends a message to the log destination with an info severity.

```
public function info(string $message, array $context = []): Syslog
```

**Note**

The keys of the context should respect the following format: lower case, numbers, with underscores and periods only.

**Exception**

`InvalidArgumentException`:

- If the message is empty
- If the context does not contains an array of key-pairs values
- If one of the context keys is not properly formated

`LogicException`:

- If one of the following properties are not filled: host, post, source, device, processus

`RuntimeException`:

- If the socket creation failed
- If the message could not be sent through the socket connection

### log

[](#log)

Log using an opt-in severity parameter. This has the same effect than any other others severity logging methods.

```
public function log(string $level, string $message, array $context = []): Syslog
```

**Note**

The keys of the context should respect the following format: lower case, numbers, with underscores and periods only.

**Exception**

`InvalidArgumentException`:

- If the severity is empty
- If the severity is not one of the following: emergency, alert, critical, error, warning, notice, info, debug
- If the message is empty
- If the context does not contains an array of key-pairs values
- If one of the context keys is not properly formated

`LogicException`:

- If one of the following properties are not filled: host, post, source, device, processus

`RuntimeException`:

- If the socket creation failed
- If the message could not be sent through the socket connection

### notice

[](#notice)

Sends a message to the log destination with a notice severity.

```
public function notice(string $message, array $context = []): Syslog
```

**Note**

The keys of the context should respect the following format: lower case, numbers, with underscores and periods only.

**Exception**

`InvalidArgumentException`:

- If the message is empty
- If the context does not contains an array of key-pairs values
- If one of the context keys is not properly formated

`LogicException`:

- If one of the following properties are not filled: host, post, source, device, processus

`RuntimeException`:

- If the socket creation failed
- If the message could not be sent through the socket connection

### port

[](#port)

Set the port of the log destination server address.

```
public function port(int $port): Syslog
```

### processus

[](#processus)

Set the original processus that is responsible for this log. For more information, see the definition of this attribute on the [Syslog RFC5424 documentation](https://tools.ietf.org/html/rfc5424#section-6.2.6).

```
public function processus(string $processus): Syslog
```

### source

[](#source)

Set the original server that generated this log. For more information, see the definition of this attribute on the [Syslog RFC5424 documentation](https://tools.ietf.org/html/rfc5424#section-6.2.4).

```
public function source(string $source): Syslog
```

### warning

[](#warning)

Sends a message to the log destination with a warning severity.

```
public function warning(string $message, array $context = []): Syslog
```

**Note**

The keys of the context should respect the following format: lower case, numbers, with underscores and periods only.

**Exception**

`InvalidArgumentException`:

- If the message is empty
- If the context does not contains an array of key-pairs values
- If one of the context keys is not properly formated

`LogicException`:

- If one of the following properties are not filled: host, post, source, device, processus

`RuntimeException`:

- If the socket creation failed
- If the message could not be sent through the socket connection

Prototype ready
---------------

[](#prototype-ready)

This class lets you extend its functionality to your needs without having to dive into the source code. For example:

```
use Khalyomede\Syslog;

$log = new Syslog;

$log->prototype('oneHourAgo', function() {
  $this->date->sub(new DateInterval('PT1H'));

  return $this;
});

$log->host('log.test.com')
  ->port(12345)
  ->facility(22)
  ->source('test.test.com')
  ->device('test-website')
  ->processus('test-home')
  ->date(new DateTime)
  ->oneHourAgo();

$log->info('test');
```

For more information, check [khalyomede/prototype](https://github.com/khalyomede/prototype) documentation.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

3012d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15908747?v=4)[Anwar](/maintainers/khalyomede)[@khalyomede](https://github.com/khalyomede)

---

Top Contributors

[![khalyomede](https://avatars.githubusercontent.com/u/15908747?v=4)](https://github.com/khalyomede "khalyomede (19 commits)")

---

Tags

classcomposerpackagistphpphp7syslog

### Embed Badge

![Health badge](/badges/khalyomede-syslog/health.svg)

```
[![Health](https://phpackages.com/badges/khalyomede-syslog/health.svg)](https://phpackages.com/packages/khalyomede-syslog)
```

###  Alternatives

[sentry/sentry

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

1.9k240.0M315](/packages/sentry-sentry)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[illuminate/log

The Illuminate Log package.

6225.0M603](/packages/illuminate-log)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[api-platform/metadata

API Resource-oriented metadata attributes and factories

244.5M182](/packages/api-platform-metadata)[pagemachine/typo3-formlog

Form log for TYPO3

23233.9k8](/packages/pagemachine-typo3-formlog)

PHPackages © 2026

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