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

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

idearia/php-logger
==================

Simple logger class for PHP with time tracking

1.5(3y ago)513.1k↓100%27GPL-3.0-or-laterPHPPHP ^7.0 | ^8.0CI failing

Since May 4Pushed 3y ago6 watchersCompare

[ Source](https://github.com/Idearia/php-logger)[ Packagist](https://packagist.org/packages/idearia/php-logger)[ Docs](https://github.com/Idearia/php-logger)[ RSS](/packages/idearia-php-logger/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (1)Versions (8)Used By (0)

PHP Logger
==========

[](#php-logger)

Simple logger class to:

- Keep track of log entries.
- Keep track of timings with `time()` and `timeEnd()` methods, Javascript style.
- Optionally write log entries in real-time to file or to screen.
- Optionally dump the log to file in one go at any time.

Log entries can be added with any of the following methods:

- `debug( $message, $title = '' )` &gt; a diagnostic message intended for the developer
- `info( $message, $title = '' )` &gt; an informational message intended for the user
- `warning( $message, $title = '' )` &gt; a warning that something might go wrong
- `error( $message, $title = '' )` &gt; explain why the program is going to crash

The `$title` argument is optional; if present, it will be prepended to the message: "$title =&gt; $message".

Quick example
=============

[](#quick-example)

The following code:

```
Logger::$log_level = 'debug';
Logger::debug( "variable x is false" );
Logger::info( "program started" );
Logger::warning( "variable not set, something bad might happen" );
Logger::error( "file not found, exiting" );
```

will print to STDOUT the following lines:

```
$> 2021-07-21T11:11:03+02:00 [DEBUG] : variable x is false
$> 2021-07-21T11:11:03+02:00 [INFO] : program started
$> 2021-07-21T11:11:03+02:00 [WARNING] : variable not set, something bad might happen
$> 2021-07-21T11:11:03+02:00 [ERROR] : file not found, exiting

```

Timing
======

[](#timing)

You can keep track of elapsed time by using the `time()` and `timeEnd()` function.

### Timing example

[](#timing-example)

```
Logger::time();
sleep(1);
Logger::timeEnd();
```

will print:

```
$> 2022-04-19T17:26:26+00:00 [DEBUG] : Elapsed time => 1.003163 seconds

```

### Named timers

[](#named-timers)

If you need to time different processes at the same time, you can use named timers.

For example:

```
Logger::time('outer timer');
sleep(1);
Logger::time('inner timer');
sleep(1);
Logger::timeEnd('inner timer');
Logger::timeEnd('outer timer');
```

will print:

```
$> 2022-04-19T17:32:15+00:00 [DEBUG] : Elapsed time for 'inner timer' => 1.002268 seconds
$> 2022-04-19T17:32:15+00:00 [DEBUG] : Elapsed time for 'outer timer' => 2.006117 seconds

```

Options
=======

[](#options)

To customize the logger, you can either:

- extend the class and override the static properties or
- set the static properties at runtime.

In the following examples, we adopt the second approach.

Set the log level
-----------------

[](#set-the-log-level)

By default, the logger will assume it runs in production and, therefore, will print only error-level messages.

Specify your desired log level in the following way:

```
Logger::$log_level = 'error'; // Show only errors
Logger::$log_level = 'warning'; // Show warnings and errors
Logger::$log_level = 'info'; // Show info messages, warnings and errors
Logger::$log_level = 'debug'; // Show debug messages, info messages, warnings and errors
```

Write to file
-------------

[](#write-to-file)

To also write to file, set:

```
Logger::$write_log = true;
```

To customize the log file path:

```
Logger::$log_dir = 'logs';
Logger::$log_file_name = 'my-log';
Logger::$log_file_extension = 'log';
```

To overwrite the log file at every run of the script:

```
Logger::$log_file_append = false;
```

Do not print to screen
----------------------

[](#do-not-print-to-screen)

To prevent printing to STDOUT:

```
Logger::$print_log = false;
```

Parallel code caveat
====================

[](#parallel-code-caveat)

The class uses the static methods and internal flags (e.g. `$logger_ready`) to keep its state. We do this to make the class work straight away, without any previous configuration or the need to instantiate it. This however can create race conditions if you are executing parallel code. Please let us know if this is a problem for you, if we receive enough feedback, we will switch to a more class-like approach.

Contributing 🙂
==============

[](#contributing-)

Feel free to fork the repository and make a pull request!

Before sending the request, please make sure your code passes all the tests:

```
composer run test

```

###  Health Score

40

↑

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 76.5% 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 ~285 days

Recently: every ~135 days

Total

7

Last Release

1165d ago

PHP version history (2 changes)1.0PHP ^7.0

1.3PHP ^7.0 | ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/374087a7abcd1dcedef3fc8a7627b438828f73ab4a379a383da8cb6de7a3a2a8?d=identicon)[idearia](/maintainers/idearia)

---

Top Contributors

[![coccoinomane](https://avatars.githubusercontent.com/u/3920436?v=4)](https://github.com/coccoinomane "coccoinomane (13 commits)")[![boghy933](https://avatars.githubusercontent.com/u/7885191?v=4)](https://github.com/boghy933 "boghy933 (1 commits)")[![EvaluatedApplications](https://avatars.githubusercontent.com/u/80432183?v=4)](https://github.com/EvaluatedApplications "EvaluatedApplications (1 commits)")[![ideariasrl](https://avatars.githubusercontent.com/u/31926609?v=4)](https://github.com/ideariasrl "ideariasrl (1 commits)")[![kamilsmtv](https://avatars.githubusercontent.com/u/16596023?v=4)](https://github.com/kamilsmtv "kamilsmtv (1 commits)")

---

Tags

logloggingtime tracking

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[monolog/monolog

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

21.4k949.6M6.3k](/packages/monolog-monolog)[symfony/monolog-bundle

Symfony MonologBundle

2.9k244.8M1.4k](/packages/symfony-monolog-bundle)[sentry/sentry

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

1.9k221.1M243](/packages/sentry-sentry)[sentry/sentry-laravel

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

1.3k110.7M122](/packages/sentry-sentry-laravel)[rap2hpoutre/laravel-log-viewer

A Laravel log reader

3.2k14.4M65](/packages/rap2hpoutre-laravel-log-viewer)[sentry/sdk

This is a meta package of sentry/sentry. We recommend using sentry/sentry directly.

327133.3M140](/packages/sentry-sdk)

PHPackages © 2026

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