PHPackages                             activecollab/logger - 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. activecollab/logger

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

activecollab/logger
===================

PSR-3 logger that is easy to plug in Active Collab components

2.1.0(4mo ago)166.9k↓17.7%1MITPHPPHP &gt;=8.0CI failing

Since Jul 3Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/activecollab/logger)[ Packagist](https://packagist.org/packages/activecollab/logger)[ Docs](https://labs.activecollab.com)[ RSS](/packages/activecollab-logger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (13)Used By (1)

Logger
======

[](#logger)

This package implements some of our internal conventions on top of PSR-3. Logger that it publishes is fully PSR-3 comptabile with some extra functionality (optional), as well as a factory that makes logger creation easy:

```
$factory = new LoggerFactory();
$logger = $factory->create(
    'ActiveCollab',
    '1.0.0',
    'development',
    LoggerInterface::LOG_FOR_DEBUG,
    LoggerInterface::FILE,
    '/path/to/logs/dir'
);
```

Once logger is set, you can use it like any other PSR-3 logger:

```
$logger->info('Something interesting happened: {what}', [
    'what' => 'really interesting event'
]);
```

Special loggers are:

1. Event logging using `LoggerInterface::event()` method. This will log a named event on info level, and set event context attribute to event name,
2. Request summary logging using `LoggerInterface::requestSummary()` method. This will log some interesting request data, like executing time, total queries and query count etc.

Loggers
-------

[](#loggers)

Packages comes with following backends implemented:

`LoggerInterface::FILE` - Log to files in log directory. Log directory is required as first logger argument when creating a logger:

```
$logger = $factory->create(
    'ActiveCollab',
    '1.0.0',
    'development',
    LoggerInterface::LOG_FOR_DEBUG,
    LoggerInterface::FILE,
    '/path/to/logs/dir',
    'my-awesome-logs.txt',
    0777
);
```

Second argument is log file name, and it is optional. When skipped, system will log to `log.txt` file in the specified folder. Third argument is file permissions level. Default is 0644 when skipped, but you can specify any value (in octal notation).

Note that we set rotating file logging, where only past 7 days of logs are kept.

`LoggerInterface::GRAYLOG` - Log messages are sent to Graylog2 server using GELF formatter. Additional arguments are Graylog2 server host and port. If they are skipped, 127.0.0.1 and are used:

```
$logger = $factory->create(
    'ActiveCollab',
    '1.0.0',
    'development',
    LoggerInterface::LOG_FOR_DEBUG,
    LoggerInterface::GRAYLOG,
    'graylog.company.com',
    12201
);
```

`LoggerInterface::BLACKHOLE` - Messages are not logged anywhere.

Message Buffering
-----------------

[](#message-buffering)

Logger is built to buffer messages until request details are set (using `setAppRequest()` method). Reason why we delay writing to log is to be able to add request details to all messages, so we can connect the dots alter on:

```
// Set HTTP request from PSR-7 ServerRequestInterface
$logger->setAppRequest(new \ActiveCollab\Logger\AppRequest\HttpRequest($request));

// Set CLI request from arguments
$logger->setAppRequest(new \ActiveCollab\Logger\AppRequest\CliRequest('session ID', $_SERVER['argv']));
```

If request is not set, buffer will not be flushed unless you flush it yourself, or register a shutdown function:

```
$logger->flushBufferOnShutdown();
```

Application Details
-------------------

[](#application-details)

This package always logs application name, version and environemnt. These arguments are required and they need to be provided to `FactoryInterface::create()` method, when creating new logger instance:

```
$logger = $factory->create('ActiveCollab', '1.0.0', 'development', LoggerInterface::LOG_FOR_DEBUG, LoggerInterface::FILE, '/path/to/logs/dir');
```

Environment arguments are sent as context arguments with all messages captured via logger instance. User can specify additional environment arguments, using `FactoryInterface::setAdditionalEnvArguments()` method:

```
// Additional environment arguments can be set on factory level, and factory will pass them to all loggers that it produces
$factory->setAdditionalEnvArguments([
    'account_id' => 123,
    'extra_argument' => 'with extra value',
]);

// Or you can specify them on logger level
$logger->setAdditionalEnvArguments([
    'account_id' => 123,
    'extra_argument' => 'with extra value',
]);
```

Exception Serialization
-----------------------

[](#exception-serialization)

When exceptions are passed as context arguments, package will "explode" them to a group of relevant arguments: message, file, line, code, and trace. Previous exception is also extracted, when available:

```
try {
    // Something risky
} catch (ExceptioN $e) {
    $logger->error('An {exception} happened :(', [
        'exception' => $e,
    ]);
}
```

If you have special exceptions that collect more info than message, code, file, line, trace and previous, you can register a callback that will extract that data as well:

```
$logger->addExceptionSerializer(function ($argument_name, $exception, array &$context) {
    if ($exception instanceof \SpecialError) {
        foreach ($exception->getParams() as $k => $v) {
            $context["{$argument_name}_extra_param_{$k}"] = $v;
        }
    }
});
```

Callback gets three arguments:

1. `$argument_name` - contenxt argument name under which we found the exception,
2. `$exception_name` - exception itself,
3. `$context` - access to resulting log message context arguments.

As with additional environment variables, exception serializers can be added to factory, and factory will pass it on to all loggers that it produces:

```
$factory->addExceptionSerializer(function ($argument_name, $exception, array &$context) {
    if ($exception instanceof \SpecialError) {
        foreach ($exception->getParams() as $k => $v) {
            $context["{$argument_name}_extra_param_{$k}"] = $v;
        }
    }
});
```

Error Handling
--------------

[](#error-handling)

Logger comes equiped with a class that can register error and exception handlers and direct them to the log. Quick setup:

```
$handler = new ErrorHandler($logger);
$handler->initialize();
```

To restore error and exception handled, simply call `restore()` method:

```
$handler->restore();
```

Handler can be configured to do different things for diffent error levels. For example, you can configure it to throw an exception on PHP warning, or to silence an event all together:

```
$handler->setHowToHandleError(E_STRICT, ErrorHandlerInterface::SILENCE);
$handler->setHowToHandleError(E_DEPRECATED, ErrorHandlerInterface::LOG_NOTICE);
$handler->setHowToHandleError(E_NOTICE, ErrorHandlerInterface::LOG_ERROR);
$handler->setHowToHandleError(E_USER_ERROR, ErrorHandlerInterface::THROW_EXCEPTION);
```

By default, exceptions are logged and re-thrown. This behavior can be turned off:

```
$handler->setReThrowException(false);
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance75

Regular maintenance activity

Popularity31

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity75

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

Recently: every ~688 days

Total

12

Last Release

136d ago

Major Versions

1.3.1 → 2.0.02021-02-17

PHP version history (3 changes)1.0.0PHP &gt;=5.6.0

2.0.0PHP &gt;=7.1

2.1.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/729914?v=4)[Ilija Studen](/maintainers/ilijastuden)[@ilijastuden](https://github.com/ilijastuden)

---

Top Contributors

[![ilijastuden](https://avatars.githubusercontent.com/u/729914?v=4)](https://github.com/ilijastuden "ilijastuden (38 commits)")

---

Tags

loggeractivecollab

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/activecollab-logger/health.svg)

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

###  Alternatives

[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1851.5M3](/packages/justbetter-magento2-sentry)[theorchard/monolog-cascade

Monolog extension to configure multiple loggers in the blink of an eye and access them from anywhere

1482.2M9](/packages/theorchard-monolog-cascade)[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k7](/packages/inpsyde-wonolog)[amphp/log

Non-blocking logging for PHP based on Amp, Revolt, and Monolog.

402.6M70](/packages/amphp-log)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8674.9k](/packages/illuminated-console-logger)[logtail/monolog-logtail

Logtail handler for Monolog

233.2M3](/packages/logtail-monolog-logtail)

PHPackages © 2026

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