PHPackages                             crazyfactory/phalcon-loggers - 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. crazyfactory/phalcon-loggers

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

crazyfactory/phalcon-loggers
============================

Phalcon logging adapters for Slack and Sentry.

1.0.0(6y ago)717.7k1[1 issues](https://github.com/crazyfactory/phalcon-loggers/issues)MITPHPPHP &gt;=7.0CI failing

Since Mar 31Pushed 3y ago8 watchersCompare

[ Source](https://github.com/crazyfactory/phalcon-loggers)[ Packagist](https://packagist.org/packages/crazyfactory/phalcon-loggers)[ RSS](/packages/crazyfactory-phalcon-loggers/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (5)Used By (0)

phalcon-loggers [![build status](https://camo.githubusercontent.com/f6f5e91804f547e1c4f3c9a46af5c749b383a01a98c7a889aa9401c9ea783ffd/68747470733a2f2f6170692e7472617669732d63692e6f72672f6372617a79666163746f72792f7068616c636f6e2d6c6f67676572732e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/f6f5e91804f547e1c4f3c9a46af5c749b383a01a98c7a889aa9401c9ea783ffd/68747470733a2f2f6170692e7472617669732d63692e6f72672f6372617a79666163746f72792f7068616c636f6e2d6c6f67676572732e7376673f6272616e63683d6d6173746572)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#phalcon-loggers-)

A collection of configurable logging adapters with logging functionality loosely PSR compatible for phalcon 3.x and PHP 7.x. Currently the following adapters are implemented:

#### Sentry

[](#sentry)

- Depends on the [sentry/sentry](https://packagist.org/packages/sentry/sentry) package.
- You have to run `composer require sentry/sentry`
- You might have to require `Raven_Autoloader` as explained [here](https://docs.sentry.io/clients/php/#installation) (see #installation section below)
- Disabled by default but is active if class `Raven_Client` is defined.

#### Slack

[](#slack)

- Self contained and ready to work out of the box.

*... and we plan to add a few more!*

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

[](#installation)

It is a fully composer ready library. Just run:

```
$ composer require crazyfactory/phalcon-loggers

```

If you have not used composer's autoloading (i.e. `require 'vendor/autoload.php'`) &amp;/or just want to use phalcon's native autoloader:

```
$loader = new Phalcon\Loader;
$loader->registerNamespaces([
    'CrazyFactory\\PhalconLogger' => '/path/to/vendor/crazyfactory/phalcon-loggers/src/',
])->register();
```

If you want to use Sentry as well:

```
$ composer require sentry/sentry

```

If you have not used composer's autoloading, then setup autoloading of `Raven_` classes like so:

```
require_once '/path/to/vendor/sentry/sentry/lib/Raven/Autoloader.php';
Raven_Autoloader::register();
```

Usage
-----

[](#usage)

The easiest and quickest way to use this library is by using the supplied `Service`:

```
$id = (new Phalcon\Security\Random)->uuid();
$di = new Phalcon\Di\FactoryDefault;
(new CrazyFactory\PhalconLogger\Service)->register(null, $di);

// If you already have `requestId` in config array/object you don't need to set it again.
$di->getShared('logger')->setRequestId($id);

$di->getShared('logger')->info('some text');
// Supports interpolation for keys wrapped in curly brace.
$di->getShared('logger')->critical('some text {key}', ['key' => 'val']);

//
// Below examples assume that info level is allowed in config->slack->levels array.
//
// Mention an user in slack:
$context = ['mentions' => 'slackbot', 'a' => 10];
$di->getShared('slack')->info('some text {a}', $context);

// Customize channel, username, icon_emoji, icon_url via context:
$context += [
    'username' => 'bot',
    'channel' => '#general',
    'icon_emoji' => ':monkey_face:',
];
$di->getShared('slack')->info('some other text {a}', $context);

// Attachment:
$context += [
    'attachment' => [
        'title' => 'Attachment title',
        'text' => 'Attachment text',
        'color' => 'good',
    ],
];
$di->getShared('slack')->info('yet other text {a} with attachment', $context);
```

See [examples](examples/) for details and various integration samples. Also see the [API](#api) section.

Configuration
-------------

[](#configuration)

You can pass in configuration as an array or a file The loggers have their own configuration options but share common parameter `requestId` and `environment`. Here is how a typical configuration looks like for slack and sentry both:

```
use Phalcon\Logger;

$config = [
    // The application name used in logs. Helps to distinguish &/or search.
    'appName' => '',
    // Current application environment.
    'environment' => 'prod',
    'requestID'   => null,
    'sentry'      => [
        // The login information for Sentry. If one of the values is empty the logging is suppressed silently.
        'credential' => [
            'key'       => '',
            'secret'    => '',
            'projectId' => '',
        ],
        // The options for Raven_Client. See https://docs.sentry.io/clients/php/config/#available-settings
        'options' => [
            'curl_method' => 'sync',
            'prefixes'    => [],
            'app_path'    => '',
            'timeout'     => 2,
        ],
        // Sentry will log errors/exceptions when the application environment set above is one of these.
        'environments' => ['prod', 'staging'],
        // The log levels which are forwarded to sentry.
        'levels' => [Logger::EMERGENCY, Logger::CRITICAL, Logger::ERROR],
        // These exceptions are not reported to sentry.
        'dontReport' => [],
    ],
    'slack' => [
        // If webhook url is missing the logging is suppressed silently.
        'webhookUrl'   => '',
        // Slack will log messages when the application environment set above is one of these.
        'environments' => ['prod', 'dev'],
        // Curl method can be 'sync' or 'exec' (sync uses php curl_*, exec runs in background).
        'curlMethod'   => 'sync',
        // HTTP headers to be appended to request.
        'headers'      => [],
        // The log levels which are forwarded to slack.
        'levels'       => [Logger::SPECIAL, Logger::CUSTOM],
    ],
];

$di = new Phalcon\Di\FactoryDefault;

// Register the loggers with the config:
$di->setShared('sentry', function () use ($config) {
    return new CrazyFactory\PhalconLogger\Adapter\Sentry($config);
});
$di->setShared('slack', function () use ($config) {
    return new CrazyFactory\PhalconLogger\Adapter\Slack($config);
});

// OR you could just use supplied `Service`:
(new CrazyFactory\PhalconLogger\Service)->register($config, $di);
```

API
----------------------------------

[](#api)

All the loggers inherit from base phalcon logger [adapter](https://github.com/phalcon/cphalcon/blob/master/phalcon/logger/adapter.zep) so they automatically inherit public callable APIs from the base. In addition the loggers may also expose some APIs available for direct call.

#### Sentry:

[](#sentry-1)

Sentry logger has following public APIs:

- **addCrumb(string $message, string $category = 'default', array $data = \[\], int $type = null)**

```
    $di->getShared('sentry')->addCrumb('User has just logged in');
```

- **setTag(string $key, string $value)**

```
    $di->getShared('sentry')->setTag('name', 'value')->setTag('another', 'another-value');
```

- **setUserContext(array $context)**

```
    // you can also use current user from DI if you have one
    $di->getShared('sentry')->setUserContext(['id' => 1, 'username' => 'someone', 'email' => 'bob@example.com']);
```

- **setExtraContext(array $context)**

```
    $di->getShared('sentry')->setExtraContext(['arbitrary_key' => 'arbitrary_value', 'arbitrary_key_2', 'arbitrary_value_2']);
```

- **getLastEventId()**

```
    $di->getShared('sentry')->getLastEventId();
```

- **logException(\\Throwable $exception, array $context = \[\], int $type = null)**

```
    try {
        $app->handle();
    } catch (\Throwable $e) {
        $di->getShared('sentry')->logException($e);
        // However it is advisable to just use logException of the logger collection
        // so that all the registered loggers are notified of the exception to do the needful.
        $di->getShared('logger')->logException($e);
    }
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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

Every ~348 days

Total

4

Last Release

2281d ago

Major Versions

v0.0.4 → 1.0.02020-02-11

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2908547?v=4)[Jitendra Adhikari](/maintainers/adhocore)[@adhocore](https://github.com/adhocore)

---

Top Contributors

[![adhocore](https://avatars.githubusercontent.com/u/2908547?v=4)](https://github.com/adhocore "adhocore (17 commits)")

---

Tags

adapterloggerphalconsentryslackloggingslacksentryloggerphalconadpatersphalcon-slackphalcon-sentry

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/crazyfactory-phalcon-loggers/health.svg)

```
[![Health](https://phpackages.com/badges/crazyfactory-phalcon-loggers/health.svg)](https://phpackages.com/packages/crazyfactory-phalcon-loggers)
```

###  Alternatives

[sentry/sentry

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

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

Laravel SDK for Sentry (https://sentry.io)

1.3k114.3M154](/packages/sentry-sentry-laravel)[sentry/sentry-symfony

Symfony integration for Sentry (http://getsentry.com)

73761.4M66](/packages/sentry-sentry-symfony)[sentry/sdk

This is a meta package of sentry/sentry. We recommend using sentry/sentry directly.

327134.8M151](/packages/sentry-sdk)[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1851.5M3](/packages/justbetter-magento2-sentry)[analog/analog

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

3451.5M24](/packages/analog-analog)

PHPackages © 2026

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