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

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

socarrat/logging
================

Robust logging library for every application.

v0.2.0(3y ago)171MITPHPCI passing

Since May 7Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (1)

Socarrat\\Logging
=================

[](#socarratlogging)

Robust logging library for every application.

Features
--------

[](#features)

- Simple yet reliable logging.
- Supports every type of output you like.
- You can [write your own logger implementation](#abstract-class-socarratlogginglogger) if you need something custom.
- Multiple output streams.
- [Static methods](#static-public-function-logloglevel-level-string-message): call the logger from whichever part of your application without needing to have a reference to some logging object!
- [Minimum log levels](#static-public-function-setminimumloglevelloglevel-level).

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

[](#installation)

You can install this library through Packagist: [`composer require socarrat/logging`](https://packagist.org/packages/socarrat/logging).

Examples
--------

[](#examples)

```
use Socarrat\Logging\Loggers\FileLogger;
use Socarrat\Logging\LoggingManager;
use Socarrat\Logging\LogLevel;

$fileLogger = new FileLogger(
	getFilePath: function(LogLevel $level, string $msg) {
		$l = strtolower($level->toString());
		return __DIR__."/test.$l.log";
	}
);

LoggingManager::addLogger($fileLogger);
LoggingManager::setMinimumLogLevel(LogLevel::LOG_WARNING);

LoggingManager::log(LogLevel::LOG_CRITICAL, "Hello CRITICAL"); //=> logs to test.critical.log
LoggingManager::log(LogLevel::LOG_ERROR, "Hello ERROR");       //=> logs to test.debug.log
LoggingManager::log(LogLevel::LOG_WARNING, "Hello WARNING");   //=> logs to test.warning.log

LoggingManager::log(LogLevel::LOG_NOTICE, "Hello NOTICE");     //=> will not be logged due to minimum log level log
LoggingManager::log(LogLevel::LOG_INFO, "Hello INFO");         //=> will not be logged
LoggingManager::log(LogLevel::LOG_DEBUG, "Hello DEBUG");       //=> will not be logged
```

You can find the output of this script [here](./examples/filelogger/). See more examples in the [`examples/`](./examples/) directory.

Built-in loggers
----------------

[](#built-in-loggers)

The following loggers are shipped with this library under the namespace `Socarrat\Logging\Loggers`. You could also implement your own loggers; see the [`Logger` interface](#abstract-class-socarratlogginglogger) and [`LoggingManager::addLogger`](#static-public-function-addloggerlogger-logger-int).

### `FileLogger`

[](#filelogger)

Outputs logs into a file.

#### `new FileLogger(\Closure $getFilePath)`

[](#new-fileloggerclosure-getfilepath)

Constructs a new file logger. You can pass a closure into the constructor, which is called on each log and returns the filename the log should be sent to. It receives two positional arguments: the [`LogLevel`](#enum-socarratloggingloglevel-int) and the string to log.

You can replace the filepath getter later on by calling `FileLogger::setFilePathGetter(\Closure $getFilePath)`.

### `NullLogger`

[](#nulllogger)

This logger does nothing with the logs.

API
---

[](#api)

### `class Socarrat\Logging\LoggingManager`

[](#class-socarratloggingloggingmanager)

This is the central logging manager; you should use this to log things.

#### `static public function addLogger(Logger $logger): int`

[](#static-public-function-addloggerlogger-logger-int)

Adds a [logger](#abstract-class-socarratlogginglogger) instance to use. Returns the index which has been assigned to the logger. If multiple loggers have been set, each of them is called.

Parameter nameTypeDefault valueDescription`$logger``Logger`-The logger instance to add.#### `static public function log(LogLevel $level, string $message)`

[](#static-public-function-logloglevel-level-string-message)

Logs the given message at the given log level using [the logger that has been set](#static-public-function-addloggerlogger-logger-int). If multiple loggers have been set, each of them is called.

Parameter nameTypeDefault valueDescription`$level``LogLevel`-The level at which to log.`$message``string`-The log message.#### `static public function setMinimumLogLevel(LogLevel $level)`

[](#static-public-function-setminimumloglevelloglevel-level)

Sets the minimum [log level](#enum-socarratloggingloglevel-int). Log messages that have a lower level will not be logged.

Example: the minimum log level is `LOG_NOTICE`. Logs with `LOG_DEBUG` will not be logged, unlike `LOG_ERROR` logs.

Parameter nameTypeDefault valueDescription`$level``LogLevel`-The minimum level at which to log.### `abstract class Socarrat\Logging\Logger`

[](#abstract-class-socarratlogginglogger)

This is the base class for loggers. All loggers should extend it.

#### `abstract public function log(LogLevel $level, string $message)`

[](#abstract-public-function-logloglevel-level-string-message)

Logs the given message at the given log level. You should not call this directly, use [`LogManager::log`](#static-public-function-logloglevel-level-string-message) instead.

Parameter nameTypeDefault valueDescription`$level``LogLevel`-The level at which to log.`$message``string`-The log message.### `enum Socarrat\Logging\LogLevel: int`

[](#enum-socarratloggingloglevel-int)

Contains the [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424) log levels.

Log levelSituationID`LOG_EMERGENCY`System is unusable.`2``LOG_ALERT`Action must be taken immediately.`2``LOG_CRITICAL`Critical conditions.`2``LOG_ERROR`Error conditions.`3``LOG_WARNING`Warning conditions.`4``LOG_NOTICE`Notice: normal but significant conditions.`5``LOG_INFO`Informational messages.`6``LOG_DEBUG`Debug-level messages.`7``LogLevel::toString()` will return the stringified version of the log level, e.g. calling `(LogLevel::LOG_ALERT)->toString()` will result in `ALERT`.

Copyright
---------

[](#copyright)

(c) 2023 Romein van Buren. Licensed under the MIT license.

For the full copyright and license information, please view the [`license.md`](./license.md) file that was distributed with this source code.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity35

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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1106d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/80e830e4767cfe6a30503054d4b2c80b571bb5e8ec22ceddf28191e8a58f07f0?d=identicon)[Roman1001](/maintainers/Roman1001)

---

Top Contributors

[![garraflavatra](https://avatars.githubusercontent.com/u/34036573?v=4)](https://github.com/garraflavatra "garraflavatra (13 commits)")

---

Tags

logging

### Embed Badge

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

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

###  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)
