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

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

ap-lib/logger
=============

A performance-focused and flexible library for logging, supporting errors, warnings, info, and debug messages.

047PHP

Since Mar 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ap-lib/logger)[ Packagist](https://packagist.org/packages/ap-lib/logger)[ RSS](/packages/ap-lib-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

AP\\Logger
==========

[](#aplogger)

[![MIT License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

A performance-focused and flexible PHP library for logging, supporting errors, warnings, info, and debug messages.

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

[](#installation)

```
composer require ap-lib/logger
```

Features
--------

[](#features)

- Supports log separation by modules
- Allows different logging strategies for each module
- Enables easy creation of custom log strategies

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

[](#requirements)

- PHP 8.3 or higher

Getting started
---------------

[](#getting-started)

### Log level

[](#log-level)

```
use AP\Logger\Log;

Log::error("message");
Log::warn("message");
Log::info("message");
Log::debug("message");
```

### Additonal info and modules

[](#additonal-info-and-modules)

```
use AP\Logger\Log;

// some error
Log::error("message");

// some error with additional information
Log::error("message", [
    "foo1" => "boo1"
    "foo2" => "boo2"
]);

// error for some module
Log::error("message", module: "module_name");

// some error with additional information for some module
Log::error(
    "message",
    [
        "foo1" => "boo1"
        "foo2" => "boo2"
    ],
    "module_name"
);
```

### For large modules, having a dedicated logger can be helpful

[](#for-large-modules-having-a-dedicated-logger-can-be-helpful)

```
class MyLog extends Log
{
    protected static function defaultModule(): string
    {
        return "myModule";
    }
}

MyLog::info("hello"); // 2025-01-31 23:34:05.778400 myModule::[INFO] hello
Log::info("hello"); // 2025-01-31 23:34:05.778446 app::[INFO] hello
```

### Custom dumper

[](#custom-dumper)

This example demonstrates how to batch log entries to a remote server. For simplicity, it writes to a file, but the approach can be adapted for network transmission.

```
use AP\Logger\Action;
use AP\Logger\Dumper\AddInterface;
use AP\Logger\Dumper\CommitInterface;

class MyLogDumper implements AddInterface, CommitInterface
{
    private array $lines = [];

    public function __construct(
        readonly string $filename,
        readonly int $batch_limit,
    )
    {
    }

    public function add(Action $action): void
    {
        print_r($this->lines);

        $this->lines[] = "$action->microtime [{$action->level->name}] $action->message";
        if (count($this->lines) == $this->batch_limit) {
            $this->commit();
        }
    }

    public function commit(): void
    {
        $content = "######################" . "\n";
        foreach ($this->lines as $line) {
            $content .= $line . "\n";
        }
        file_put_contents($this->filename, $content, FILE_APPEND);
        $this->lines = [];
    }
}
```

```
use AP\Logger\Log;

Log::router()->setDefaultDumper(new MyLogDumper(
    filename: "logs.txt",
    batch_limit: 5
));

Log::info("hello 1");
Log::info("hello 2");
Log::info("hello 3");
Log::info("hello 4");
Log::info("hello 5");
Log::info("hello 6");
Log::info("hello 7");
```

logs.txt file will include:

```
######################
1738367282.3243 [INFO] hello 1
1738367282.3243 [INFO] hello 2
1738367282.3243 [INFO] hello 3
1738367282.3243 [INFO] hello 4
1738367282.3243 [INFO] hello 5
######################
1738367282.3244 [INFO] hello 6
1738367282.3244 [INFO] hello 7

```

### Lazy load and use different dumpers for production and development environments

[](#lazy-load-and-use-different-dumpers-for-production-and-development-environments)

By default, error log output no included: debug info, trace and additional info It is good practice to set up different log dumper for dev and production environment

Using Boot helpers is a good approach:

```
use AP\Logger\Dumper\ErrorLog;
use AP\Logger\Level;
use AP\Logger\Log;
use AP\Logger\Router;

class Boot
{
    public static function isProduction(): bool
    {
        return false;
    }

    public static function initLog(Router $router)
    {
        if (self::isProduction()) {
            $router->setDefaultDumper(new MyLogDumper());
        } else {
            $router->setDefaultDumper(
                new ErrorLog(
                    log_level: Level::DEBUG,
                    print_context: true,
                    print_trace: true,
                    timezone: "pst"
                )
            );
        }
    }

    public static function initCore()
    {
        // Set up lazy initialization for the router, it'll initialize only if used
        Log::routerLazyInit([self::class, "initLog"]);
    }
}
```

Use it to pre-initialize the environment

```
Boot::initCore();

Log::info("hello world");
```

If you need to route logs to different dumpers based on log levels, you can implement a routing dumper.

### Exceptions normalizer included by default

[](#exceptions-normalizer-included-by-default)

```
use AP\Logger\Log;

function test1()
{
    try {
        throw new RuntimeException("hello exception");
    } catch (Throwable $e) {
        Log::error("error", context: $e);
    }
}

function test2()
{
    try {
        throw new RuntimeException("hello exception");
    } catch (Throwable $e) {
        Log::error("error", context: [
            "place"     => "test2",
            "exception" => $e,
        ]);
    }
}

function main()
{
    test1();
    test2();
}

main();
```

result:

```
php /code/readme_example_exception.php

2025-02-03 22:32:31.657456 app::[ERROR] error
  data:
    [type] => RuntimeException
    [message] => hello exception
    [file] => /code/readme_example_exception.php
    [line] => 10
    [code] => 0

2025-02-03 22:32:31.657527 app::[ERROR] error
  data:
    [place] => test2
    [exception] => Array
        (
            [type] => RuntimeException
            [message] => hello exception
            [file] => /code/readme_example_exception.php
            [line] => 19
            [code] => 0
        )
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1215fe5ecc9ba0ab1c730d3c992125cf6ebf460562e66be71ebae127789d465a?d=identicon)[AntonPanfilov](/maintainers/AntonPanfilov)

---

Top Contributors

[![anton-panfilov](https://avatars.githubusercontent.com/u/1083546?v=4)](https://github.com/anton-panfilov "anton-panfilov (13 commits)")

### Embed Badge

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

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

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

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