PHPackages                             dbeurive/log - 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. dbeurive/log

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

dbeurive/log
============

This package implements a simple logging service that writes messages into files

2.0.4(7y ago)019MITPHPPHP &gt;=5.6.0

Since Jan 26Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dbeurive/log)[ Packagist](https://packagist.org/packages/dbeurive/log)[ RSS](/packages/dbeurive-log/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (7)Used By (0)

Description
===========

[](#description)

This package implements a simple logging service that writes messages into files.

**Note**

> Please note that the LOG file is opened and closed each time a message is added to the file. Relatively to performance, this strategy is not the best one. However, it makes the management of LOG files easier. If you've ever faced a *dereferenced file*, then you understand why.
>
> In practice, a *dereferenced file* is a file that does not show up when you list the content of a directory, although it really exists in the directory. And you often face this situation when you notice that the partition gets full : the amount of free space gets lower and lower, but the sizes of all (visible) files in the partition don't change. Typically, a process opens a (LOG) file and this file gets deleted while it is still opened (and written to) by the process.

Synopsis
========

[](#synopsis)

```
use dbeurive\Log\Logger;

// Available level:
//
// * Logger::LEVEL_FATAL
// * Logger::LEVEL_ERROR
// * Logger::LEVEL_WARNING
// * Logger::LEVEL_SUCCESS
// * Logger::LEVEL_INFO
// * Logger::LEVEL_DATA
// * Logger::LEVEL_DEBUG

// 20190126111327 5c4c32c743390 FATAL R This is a fatal error
// 20190126111327 5c4c32c743390 ERROR R This is a standard error

$logger = new Logger('log-info.log', Logger::LEVEL_INFO);

$logger->fatal("This is a fatal error");
$logger->error("This is a standard error");
$logger->warning("This is a warning");
$logger->success("This is a success");
$logger->info("This is a informative message");
$logger->info("This is a multiline informative message\nother line.");

$logger->data("This is a data");   // Not written
$logger->data(array('a' => 1));    // Not written
$logger->debug('This is a debug'); // Not written

// 20190126111327 123 FATAL R This is a fatal error
// 20190126111327 123 ERROR R This is a standard error

$session_id = '123456';
$logger = new Logger('log-info.log', Logger::LEVEL_INFO, $session_id);

$logger->fatal("This is a fatal error");
$logger->error("This is a standard error");

```

The logger produces logs that look like:

```
Timestamp SessionId Level LinearizationFlag Message

```

The timestamp format is "`YYYYMMDDHHMMSS`":

- `YYYY`: four-digit representation for the year.
- `MM`: two-digit representation of the month (with leading zeros).
- `DD`: two-digit representation of the day of the month (with leading zeros).
- `HH`: two-digit representation of the hour in 24-hour format (with leading zeros).
- `MM`: two-digit representation of the minute (with leading zeros).
- `SS`: two-digit representation of the second (with leading zeros).

If no session is specified, then the Logger constructor creates a session ID by calling `uniqid()`.

The level can be: `FATAL`, `ERROR`, `WARNING`, `INFO`, `DATA` or `DEBUG`.

The linearization flag may be `L` or `R`:

- `L`: linearized. This value indicates that the message has been linearized. Messages are linearised because they are made of more than one line. You can get the original value from the linearized one by calling the method `Logger::delinearize($linearized_message)`. Please note that the linearisation algorithm is the one used for [URI encoding](http://www.faqs.org/rfcs/rfc3986.html).
- `R`: Raw. This value indicates that the message has been written without modification.

Installation
============

[](#installation)

From the command line:

```
composer require dbeurive/log

```

From your composer.json file:

{ "require": { "dbeurive/log": "\*" } }

API
===

[](#api)

Constructor
-----------

[](#constructor)

`__construct($in_path, $in_level, $in_opt_session_id=null)`

- `$in_path`: path to the LOG file.
- `$in_level` can be:
    - `Logger::LEVEL_FATAL`: only messages tagged "FATAL" will be printed to the LOG file.
    - `Logger::LEVEL_ERROR`: only messages tagged "FATAL" and "ERROR" will be printed to the LOG file.
    - `Logger::LEVEL_WARNING`: only messages tagged "FATAL", "ERROR" and "WARNING" will be printed to the LOG file.
    - `Logger::LEVEL_SUCCESS`: only messages tagged "FATAL", "ERROR", "WARNING" and "SUCCESS" will be printed to the LOG file.
    - `Logger::LEVEL_INFO`: only messages tagged "FATAL", "ERROR", "WARNING", "SUCCESS" and "INFO" will be printed to the LOG file.
    - `Logger::LEVEL_DATA`: only messages tagged "FATAL", "ERROR", "WARNING", "SUCCESS", "INFO" and "DATA" will be printed to the LOG file.
    - `Logger::LEVEL_DEBUG`: all messages will be printed to the LOG file.
- `$in_opt_session_id`: optional session ID. This string will be added to all lines of LOGs.

Object methods
--------------

[](#object-methods)

- `setNewLine(string $in_delimiter)`: set the sequence of characters used as the new line delimiter. The default value is "\\n".
- `fatal(string $in_message)`: log a fatal error.
- `error(string $in_message)`: log ane error error.
- `warning(string $in_message)`: log a warning message.
- `success(string $in_message)`: log a success message.
- `info(string $in_message)`: log an informative message.
- `data(mixed $in_message)`: log a message (string, numerical value or boolean) or a data (array, object or resource).
- `debug(string $in_message)`: log a debug message.

Class methods
-------------

[](#class-methods)

- `needLinearization(string $in_text)`: test whether a text needs to be linearised or not.
- `linearize(string $in_text)`: linearize a given text.
- `delinearize(string $in_text)`: delinearize a given text.
- `getLevelFromName($in_level_name)`: Return the integer value that represents a given level name, identified by its name.

The [API](src/Logger.php) is very simple, heavily documented, and you can see [this example](examples/app.php).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

Total

6

Last Release

2653d ago

Major Versions

1.0.0 → 2.0.02019-01-27

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18211524?v=4)[Denis BEURIVE](/maintainers/dbeurive)[@dbeurive](https://github.com/dbeurive)

---

Top Contributors

[![dbeurive](https://avatars.githubusercontent.com/u/18211524?v=4)](https://github.com/dbeurive "dbeurive (9 commits)")

---

Tags

logfile

### Embed Badge

![Health badge](/badges/dbeurive-log/health.svg)

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

###  Alternatives

[monolog/monolog

Sends your logs to files, sockets, inboxes, databases and various web services

21.4k964.9M7.0k](/packages/monolog-monolog)[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[symfony/monolog-bundle

Symfony MonologBundle

2.9k249.1M1.6k](/packages/symfony-monolog-bundle)[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k227.1M273](/packages/sentry-sentry)[sentry/sentry-laravel

Laravel SDK for Sentry (https://sentry.io)

1.3k114.3M154](/packages/sentry-sentry-laravel)

PHPackages © 2026

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