PHPackages                             tobento/app-logging - 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. tobento/app-logging

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

tobento/app-logging
===================

App logging support.

2.0(7mo ago)0121↓33.3%9MITPHPPHP &gt;=8.4

Since Nov 24Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/app-logging)[ Packagist](https://packagist.org/packages/tobento/app-logging)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-app-logging/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (5)Dependencies (14)Versions (7)Used By (9)

App Logging
===========

[](#app-logging)

Logging support for the app using the [Monolog](https://github.com/Seldaek/monolog) library.

Table of Contents
-----------------

[](#table-of-contents)

- [Getting Started](#getting-started)
    - [Requirements](#requirements)
- [Documentation](#documentation)
    - [App](#app)
    - [Logging Boot](#logging-boot)
        - [Logging Config](#logging-config)
    - [Logger Trait](#logger-trait)
    - [Loggers](#loggers)
        - [Lazy Loggers](#lazy-loggers)
    - [Logger Factories](#Logger-factories)
        - [Stack Logger Factory](#stack-logger-factory)
    - [Events](#events)
    - [Interfaces](#interfaces)
        - [Loggers Interface](#loggers-interface)
        - [Logger Factory Interface](#logger-factory-interface)
- [Credits](#credits)

---

Getting Started
===============

[](#getting-started)

Add the latest version of the app logging project running this command.

```
composer require tobento/app-logging

```

Requirements
------------

[](#requirements)

- PHP 8.4 or greater

Documentation
=============

[](#documentation)

App
---

[](#app)

Check out the [**App Skeleton**](https://github.com/tobento-ch/app-skeleton) if you are using the skeleton.

You may also check out the [**App**](https://github.com/tobento-ch/app) to learn more about the app in general.

Logging Boot
------------

[](#logging-boot)

The logging boot does the following:

- installs and loads logging config file
- implements logging interfaces

```
use Tobento\App\AppFactory;
use Tobento\App\Logging\LoggersInterface;
use Psr\Log\LoggerInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Logging\Boot\Logging::class);
$app->booting();

// Implemented interfaces:
$logger = $app->get(LoggerInterface::class);
$loggers = $app->get(LoggersInterface::class);

// Run the app
$app->run();
```

### Logging Config

[](#logging-config)

The configuration for the logging is located in the `app/config/logging.php` file at the default App Skeleton config location where you can specify the loggers for your application.

The [Lazy Loggers](#lazy-loggers) is used for the loggers.

Logger Trait
------------

[](#logger-trait)

You may use the logger trait to quickly access a logger instance and log messages:

```
use Tobento\App\Logging\LoggerTrait;

class SomeService
{
    use LoggerTrait;

    public function someAction(): void
    {
        $this->getLogger()->info('Some info');
        // is same as:
        $this->getLogger(name: static::class)->info('Some info');
        // if the named logger does not exists,
        // the default logger will be used.

        // or using another named logger:
        $this->getLogger(name: 'daily')->info('Some info');
    }
}
```

Next, you may define the logger used for your service.

In the [Logging Config](#logging-config) file, define your service class and the logger you want to use:

```
/*
|--------------------------------------------------------------------------
| Aliases
|--------------------------------------------------------------------------
*/

'aliases' => [
    SomeService::class => 'daily',
],
```

Alternatively, you may request the `LoggersInterface::class` from your app or inject it in any class and use the `addAlias` method:

```
use Tobento\App\Logging\LoggersInterface;

$app->get(LoggersInterface::class)->addAlias(alias: SomeService::class, logger: 'daily');
```

Loggers
-------

[](#loggers)

### Lazy Loggers

[](#lazy-loggers)

The `LazyLoggers::class` creates the loggers only on demand.

```
use Tobento\App\Logging\LazyLoggers;
use Tobento\App\Logging\LoggerFactoryInterface;
use Tobento\App\Logging\LoggersInterface;
use Tobento\App\Logging\StackLoggerFactory;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

$loggers = new LazyLoggers(
    container: $container, // ContainerInterface
    loggers: [
        // using a closure:
        'daily' => static function (string $name, ContainerInterface $c): LoggerInterface {
            // create logger ...
            return $logger;
        },

        // using a factory:
        'stacked' => [
            // factory must implement LoggerFactoryInterface
            'factory' => StackLoggerFactory::class,
            'config' => [
                'loggers' => ['daily', 'another'],
            ],
        ],

        // or you may sometimes just create a logger (not lazy):
        'null' => new NullLogger(),
    ],
);

var_dump($loggers instanceof LoggersInterface);
// bool(true)
```

Check out the [Logger Factories](#logger-factories) section for the available logger factories.

Check out the [Loggers Interface](#loggers-interface) section to learn more about it.

Logger Factories
----------------

[](#logger-factories)

### Stack Logger Factory

[](#stack-logger-factory)

The `StackLoggerFactory::class` creates a stack logger with the specified loggers.

```
use Tobento\App\Logging\StackLoggerFactory;
use Tobento\App\Logging\LoggerFactoryInterface;
use Tobento\App\Logging\LoggersInterface;

$factory = new StackLoggerFactory(
    loggers: $loggers // LoggersInterface
);

var_dump($factory instanceof LoggerFactoryInterface);
// bool(true)
```

Check out the [Loggers](#loggers) section for the available loggers.

**Create logger**

```
use Psr\Log\LoggerInterface;
use Tobento\App\Logging\StackLogger;

$logger = $factory->createLogger(name: 'stacked', config: [
    // specify the loggers you want to be stacked:
    'loggers' => ['daily', 'syslog'],
]);

var_dump($logger instanceof LoggerInterface);
// bool(true)

var_dump($logger instanceof StackLogger);
// bool(true)
```

Events
------

[](#events)

**Available Events**

```
use Tobento\App\Logging\Event;
```

EventDescription`Event\MessageLogged::class`The event will dispatch **when** a message is logged**Events Support**

You may add the `EventHandler::class` in the [Logging Config](#logging-config) file and install the [App Event](https://github.com/tobento-ch/app-event) bundle to support events.

```
use Tobento\App\Logging\Monolog\EventHandler;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

'loggers' => [

    'daily' => static function (string $name, ContainerInterface $c): LoggerInterface {
        return new Logger(
            name: $name,
            handlers: [
                // support events:
                $c->get(EventHandler::class),
            ],
        );
    },
],
```

Interfaces
----------

[](#interfaces)

### Loggers Interface

[](#loggers-interface)

Check out the available [Loggers](#loggers) implementing the `Tobento\App\Logging\LoggersInterface::class`.

**add**

With the `add` method you can add a new logger:

```
use Psr\Log\LoggerInterface;

$loggers->add(name: 'daily', logger: $logger); // LoggerInterface

// or using a closure:
$loggers->add(name: 'daily', logger: static function (): LoggerInterface {
    return $createdLogger;
});
```

**addAlias**

With the `addAlias` method you can add an alias for the specified logger:

```
$loggers->addAlias(alias: 'alias', logger: 'daily');

// get a logger by an alias:
$logger = $loggers->get('alias');
// returns the 'daily' logger if exists.
```

**aliases**

The `aliases` method returns the added aliases:

```
$loggers->addAlias(alias: 'alias', logger: 'daily');

$aliases = $loggers->aliases();
// ['alias' => 'daily']
```

**logger**

The `logger` method returns a logger:

```
use Psr\Log\LoggerInterface;

// get the default logger:
$logger = $loggers->logger();

// get a named logger:
$logger = $loggers->logger(name: 'daily');

// get an aliased logger:
$logger = $loggers->logger(name: 'alias');

var_dump($logger instanceof LoggerInterface);
// bool(true)
```

**get**

The `get` method returns a logger if exists, otherwise `null`:

```
use Psr\Log\LoggerInterface;

// get a named logger:
$logger = $loggers->get(name: 'daily');

// get an aliased logger:
$logger = $loggers->get(name: 'alias');

var_dump($logger instanceof LoggerInterface);
// bool(true) or NULL if not exist
```

**has**

The `has` method returns `true` if the logger exists, otherwise `false`:

```
$has = $loggers->has(name: 'daily');

// with an alias:
$has = $loggers->has(name: 'alias');
```

**names**

The `names` method returns all logger names:

```
$names = $loggers->names();

var_dump($names);
// array(1) {[0]=> string(5) "daily"}
```

**created**

The `created` method returns all created loggers which may be used to reset or clear loggers:

```
use Psr\Log\LoggerInterface;

$loggers = $loggers->created();
// array
```

### Logger Factory Interface

[](#logger-factory-interface)

Check out the available [Logger Factories](#logger-factories) implementing the `Tobento\App\Logging\LoggerFactoryInterface::class`.

**createLogger**

The `createLogger` method creates a new logger instance based on the configuration:

```
use Psr\Log\LoggerInterface;

$logger = $loggerFactory->createLogger(
    name: 'stacked', // a logger name
    config: [], // any data for creating the logger
);

var_dump($logger instanceof LoggerInterface);
// bool(true)
```

Credits
=======

[](#credits)

- [Tobias Strub](https://www.tobento.ch)
- [All Contributors](../../contributors)
- [Seldaek Monolog](https://github.com/Seldaek/monolog)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance63

Regular maintenance activity

Popularity12

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

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

Recently: every ~147 days

Total

7

Last Release

226d ago

Major Versions

1.x-dev → 2.02025-10-02

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/055d6a1b5c2384bb179c75ab0b55914231d898fdc4dffeb30770f81200e52206?d=identicon)[TOBENTOch](/maintainers/TOBENTOch)

---

Top Contributors

[![tobento-ch](https://avatars.githubusercontent.com/u/16684832?v=4)](https://github.com/tobento-ch "tobento-ch (16 commits)")

---

Tags

logloggingpackageapptobento

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tobento-app-logging/health.svg)

```
[![Health](https://phpackages.com/badges/tobento-app-logging/health.svg)](https://phpackages.com/packages/tobento-app-logging)
```

###  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)[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)[oanhnn/laravel-logzio

Integrate Logz.io into PHP and Laravel 5.6+ Application

1062.8k](/packages/oanhnn-laravel-logzio)[markrogoyski/simplelog-php

Powerful PSR-3 logging. So easy, it's simple.

2818.1k4](/packages/markrogoyski-simplelog-php)

PHPackages © 2026

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