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

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

initphp/logger
==============

PSR-3 Logger Library

1.0.1(2y ago)216811MITPHPPHP &gt;=5.6

Since Mar 15Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (1)Versions (4)Used By (1)

InitPHP Logger
==============

[](#initphp-logger)

Logger class in accordance with PSR-3 standards

[![Latest Stable Version](https://camo.githubusercontent.com/abf4725aa8076880d04d7d9f99904b48de795cee431ebe76ab963f0957b3dada/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f6c6f676765722f76)](https://packagist.org/packages/initphp/logger) [![Total Downloads](https://camo.githubusercontent.com/c73eef910d6ecb65a73b03377efb7f0e565770a373d45ba4ef783baca51a19fd/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f6c6f676765722f646f776e6c6f616473)](https://packagist.org/packages/initphp/logger) [![Latest Unstable Version](https://camo.githubusercontent.com/7d1079b11cdd4da3213a266efbeb406861d217ca0e1029fee38de0d160636b28/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f6c6f676765722f762f756e737461626c65)](https://packagist.org/packages/initphp/logger) [![License](https://camo.githubusercontent.com/4ae10716c93c74df7d9e801801df60c15884f7309df4971717273b6b8a47d95e/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f6c6f676765722f6c6963656e7365)](https://packagist.org/packages/initphp/logger) [![PHP Version Require](https://camo.githubusercontent.com/2ee42f2d3158cbb47438e9c4ec80474b5e55659bfe89caa08c1e53577c05b507/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f6c6f676765722f726571756972652f706870)](https://packagist.org/packages/initphp/logger)

Features
--------

[](#features)

- Keeping logs to the database with PDO.
- Printing log records to a file.
- Logging feature with multiple drivers.

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

[](#requirements)

- PHP 5.6 or higher
- [PSR-3 Interface Package](https://www.php-fig.org/psr/psr-3/)
- PDO Extension (Only `PDOLogger`)

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

[](#installation)

```
composer require initphp/logger

```

Using
-----

[](#using)

### FileLogger

[](#filelogger)

```
require_once "vendor/autoload.php";
use \InitPHP\Logger\Logger;
use \InitPHP\Logger\FileLogger;

$logFile = __DIR__ . '/logfile.log';

$logger = new Logger(new FileLogger(['path' => $logFile]));
```

### PdoLogger

[](#pdologger)

```
require_once "vendor/autoload.php";
use \InitPHP\Logger\Logger;
use \InitPHP\Logger\PDOLogger;

$table = 'logs';
$pdo = new \PDO('mysql:dbname=project;host=localhost', 'root', '');

$logger = new Logger(new PDOLogger(['pdo' => $pdo, 'table' => $table]));

$logger->error('User {user} caused an error.', array('user' => 'muhametsafak'));
// INSERT INTO logs (level, message, date) VALUES ('ERROR', 'User muhametsafak caused an error.', '2022-03-11 13:05:45')
```

You can use the following SQL statement to create a sample MySQL table.

```
CREATE TABLE `logs` (
    `level` ENUM('EMERGENCY','ALERT','CRITICAL','ERROR','WARNING','NOTICE','INFO','DEBUG') NOT NULL,
    `message` TEXT NOT NULL,
    `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
```

### Multi Logger

[](#multi-logger)

```
require_once "vendor/autoload.php";
use \InitPHP\Logger\Logger;
use \InitPHP\Logger\PDOLogger;
use \InitPHP\Logger\FileLogger;

$logFile = __DIR__ . '/logfile.log';

$table = 'logs';
$pdo = new \PDO('mysql:dbname=project;host=localhost', 'root', '');

$logger = new Logger(new FileLogger(['path' => $logFile]), new PDOLogger(['pdo' => $pdo, 'table' => $table]));
```

Methods
-------

[](#methods)

```
public function emergency(string $msg, array $context = array()): void;

public function alert(string $msg, array $context = array()): void;

public function critical(string $msg, array $context = array()): void;

public function error(string $msg, array $context = array()): void;

public function warning(string $msg, array $context = array()): void;

public function notice(string $msg, array $context = array()): void;

public function info(string $msg, array $context = array()): void;

public function debug(string $msg, array $context = array()): void;

public function log(string $level, string $msg, array $context = array()): void;
```

All of the above methods are used the same way, except for the `log()` method. You can use the `log()` method for your own custom error levels.

**Example 1 :**

```
$logger->emergency("Something went wrong");
```

It prints an output like this to the log file.

```
2021-09-29T13:34:47+02:00 [EMERGENCY] Something went wrong

```

**Example 2:**

```
$logger->error("User {username} caused an error.", ["username" => "john"]);
```

It prints an output like this to the log file.

```
2021-09-29T13:34:47+02:00 [ERROR] User john caused an error.

```

That is all.

---

Getting Help
------------

[](#getting-help)

If you have questions, concerns, bug reports, etc, please file an issue in this repository's Issue Tracker.

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr)

License
-------

[](#license)

Copyright © 2022 [MIT License](./LICENSE)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

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

Total

3

Last Release

884d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (1 commits)")

---

Tags

loggerphpphp-loggerphp-loggingphp-logging-librarypsr-3

### Embed Badge

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

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

###  Alternatives

[sentry/sentry

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

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

Monitors errors and exceptions and reports them to Rollbar

33723.7M82](/packages/rollbar-rollbar)[illuminate/log

The Illuminate Log package.

6224.3M518](/packages/illuminate-log)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2222.9M248](/packages/open-telemetry-sdk)[open-telemetry/api

API for OpenTelemetry PHP.

1833.0M214](/packages/open-telemetry-api)[pagemachine/typo3-formlog

Form log for TYPO3

23225.3k6](/packages/pagemachine-typo3-formlog)

PHPackages © 2026

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