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

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

sharkydog/logger
================

Simple static logger

v1.0.0(1y ago)021↓90%MITPHPPHP &gt;=7.4

Since Oct 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/sharkydog/logger)[ Packagist](https://packagist.org/packages/sharkydog/logger)[ RSS](/packages/sharkydog-logger/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

logger
======

[](#logger)

Simple static logger.

The main purpose of this package is to provide simple logging/debugging from any scope. The logger can be easily filtered, adjusted or switched off.

Logging backends and message formatting are TBD and for now everything is printed on stdout. That might change, but the public api will not without a major version bump.

Currently messages look like this:

```
[15:07:59.134][Warning] warn (tags: tag1,tag2)
[15:07:59.134][Destruct] SharkyDog\Log\Handle: bye bye handle (tags: tag)
[15:07:59.134][Memory]  495.39K (+ 495.39K), P:  558.25K, R:    2.00M (    0.00B), P:    2.00M (tags: tag1)

```

### Usage

[](#usage)

Messages are sent to the logger through several static methods that represent different logging levels. These are (low to high): `error`, `warning`, `info`, `debug`, `destruct`, `memory`.

First four have the same signature:

```
public static function error(string $msg, string ...$tags);
```

Prefix (time,level) and suffix (tags) are added to the message after it is filtered and before being printed. Tags are arbitrary strings that can be used to filter out (or in) messages.

Destruct and memory levels are special, they are higher than debug (think verbose) and have different signatures:

```
public static function destruct($object, string $msg='', string ...$tags);
public static function memory(bool $real=false, string ...$tags);
```

Destruct logs when objects are being destroyed, in three ways.

- If `$object` is a string, it is assumed to be a class name and is just logged followed by the text in `$msg` argument.
- If `$object` is an object and PHP version is 8+, the object is added to a [WeakMap](https://www.php.net/manual/en/class.weakmap.php)and data is a Handle object which when destroyed, calls `destruct()` with the class name of the object being destructed.
- If `$object` is an object and PHP version is 7.4, the Handle is set as a dynamic property to the object, named `SharkyDog\Log\Handle(handle_id)`, where `handle_id` is the id of the Handle object as returned by `spl_object_id()`. Caution should be taken when the class of the tracked object implements `__set()`.

Memory level logs `memory_get_usage()` and `memory_get_peak_usage()`. In the message:

```
[15:07:59.134][Memory]  495.39K (+ 495.39K), P:  558.25K, R:    2.00M (    0.00B), P:    2.00M (tags: tag1)

```

`P:` is the peak memory, `R:` is real memory (`memory_get_usage(true)`), `(+ 495.39K)` is the change from previous memory log. If `$real` is `true`, only real usage is logged.

#### Adjust log level

[](#adjust-log-level)

Logging level is set with:

```
public static function level(int $level);
```

Level constants are available:

- `Logger::SILENT`,`Logger::ERROR`,`Logger::WARNING`,`Logger::INFO`, `Logger::DEBUG`,`Logger::DESTRUCT`,`Logger::MEMORY`,`Logger::ALL`

Default is `Logger::WARNING`, only errors and warnings.

```
Logger::level(Logger::DEBUG);
```

This will set the level to debug and everything will be logged, except destruct and memory messages.

#### Filters

[](#filters)

Filters are callbacks executed on every message, they are added with:

```
public static function filter(int $level, callable $filter);
```

Filters can be added for a specific level or for all (`Logger::ALL`). They should follow the signature:

```
function(string $msg, array $tags, int $level): false|void;
```

Filters are called in order they were added. Returning boolean `false` will stop processing the message, no more filters will be executed and the message is discarded. You can do whatever you like with the message (and tags) before returning `false`, like save it to a file or dump it to a proper logger. A message will reach filters only if the level is set to accept it.

```
// Print only warning and info
Logger::level(Logger::INFO);
Logger::filter(Logger::ERROR, function($msg,$tags) {
  // do something with errors
});
Logger::filter(Logger::ALL, function($msg,$tags,$level) {
  if($level < Logger::WARNING) return false;
});
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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

Unknown

Total

1

Last Release

620d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d54985ab7d672df15e1ac9f278a842cddb25502a1bda7693e455680dbaa782b4?d=identicon)[SharkyDog](/maintainers/SharkyDog)

### Embed Badge

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

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

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B10.8k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1938.5M261](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2326.5M315](/packages/open-telemetry-sdk)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8676.7k](/packages/illuminated-console-logger)[relaxart/monolog-docker-handler

Docker handler for monolog

1442.6k](/packages/relaxart-monolog-docker-handler)

PHPackages © 2026

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