PHPackages                             markrogoyski/simplelog-php - 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. markrogoyski/simplelog-php

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

markrogoyski/simplelog-php
==========================

Powerful PSR-3 logging. So easy, it's simple.

v3.0.0(2mo ago)2818.1k↓26.7%94MITPHPPHP &gt;=8.1CI passing

Since Feb 13Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/markrogoyski/simplelog-php)[ Packagist](https://packagist.org/packages/markrogoyski/simplelog-php)[ Docs](https://github.com/markrogoyski/simplelog-php/)[ RSS](/packages/markrogoyski-simplelog-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (19)Versions (15)Used By (4)

[![SimpleLog Logo](https://github.com/markrogoyski/simplelog-php/raw/master/docs/image/SimpleLogLogo.png?raw=true)](https://github.com/markrogoyski/simplelog-php/blob/master/docs/image/SimpleLogLogo.png?raw=true)

SimpleLog
=========

[](#simplelog)

### Powerful PSR-3 logging. So easy, it's simple!

[](#powerful-psr-3-logging-so-easy-its-simple)

SimpleLog is a powerful PSR-3 logger for PHP that is simple to use.

Simplicity is achieved by providing great defaults. No options to configure! Yet flexible enough to meet most logging needs. And if your application's logging needs expand beyond what SimpleLog provides, since it implements PSR-3, you can drop in another great PSR-3 logger like [MonoLog](https://github.com/Seldaek/monolog) in its place when the time comes with minimal changes.

[![Coverage Status](https://camo.githubusercontent.com/32532daefee2264eb43f01603d4c11a26f70f1a3a4bbd1d06b5f16e5af0e6281/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d61726b726f676f79736b692f73696d706c656c6f672d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/markrogoyski/simplelog-php?branch=master)[![License](https://camo.githubusercontent.com/cee5890325c65e975d3f9cd5ece243537e17adf0b69dbb5d6558875ce5cc7d65/68747470733a2f2f706f7365722e707567782e6f72672f6d61726b726f676f79736b692f73696d706c656c6f672d7068702f6c6963656e7365)](https://packagist.org/packages/markrogoyski/simplelog-php)

Features
--------

[](#features)

- Power and Simplicity
- PSR-3 logger interface
- Multiple log level severities
- Log channels
- Process ID logging
- Custom log messages
- Custom contextual data
- Exception logging

Setup
-----

[](#setup)

Add the library to your `composer.json` file in your project:

```
{
  "require": {
      "markrogoyski/simplelog-php": "3.*"
  }
}
```

Use [composer](http://getcomposer.org) to install the library:

```
$ php composer.phar install
```

Composer will install SimpleLog inside your vendor folder. Then you can add the following to your .php files to use the library with Autoloading.

```
require_once(__DIR__ . '/vendor/autoload.php');
```

Alternatively, use composer on the command line to require and install SimpleLog:

```
$ php composer.phar require markrogoyski/simplelog-php:3.*

```

### Minimum Requirements

[](#minimum-requirements)

- PHP 8.1

- **Note**: For PHP 8.0, use v2.x (`markrogoyski/simplelog-php:2.*`)
- **Note**: For PHP 7.4, use v1.0 (`markrogoyski/simplelog-php:1.0`)
- **Note**: For PHP 7.0–7.3, use v0.4 (`markrogoyski/simplelog-php:0.4`)

Usage
-----

[](#usage)

### Simple 20-Second Getting-Started Tutorial

[](#simple-20-second-getting-started-tutorial)

```
$logfile = '/path/to/logfile.log';
$channel = 'events';
$logger  = new SimpleLog\Logger($logfile, $channel);

$logger->info('SimpleLog really is simple.');
```

That's it! Your application is logging!

### Extended Example

[](#extended-example)

```
$logfile = '/var/log/events.log';
$channel = 'billing';
$logger  = new SimpleLog\Logger($logfile, $channel);

$logger->info('Begin process that usually fails.', ['process' => 'invoicing', 'user' => $user]);

try {
    invoiceUser($user); // This usually fails
} catch (\Exception $e) {
    $logger->error('Billing failure.', ['process' => 'invoicing', 'user' => $user, 'exception' => $e]);
}
```

Logger output

```
2017-02-13 00:35:55.426630  [info]  [billing] [pid:17415] Begin process that usually fails. {"process":"invoicing","user":"bob"}  {}
2017-02-13 00:35:55.430071  [error] [billing] [pid:17415] Billing failure.  {"process":"invoicing","user":"bob"}  {"message":"Could not process invoice.","code":0,"file":"/path/to/app.php","line":20,"trace":[{"file":"/path/to/app.php","line":13,"function":"invoiceUser","args":["mark"]}]}

```

### Log Output

[](#log-output)

Log lines have the following format:

```
YYYY-mm-dd HH:ii:ss.uuuuuu  [loglevel]  [channel]  [pid:##]  Log message content  {"Optional":"JSON Contextual Support Data"}  {"Optional":"Exception Data"}

```

Log lines are easily readable and parsable. Log lines are always on a single line. Fields are tab separated.

### Log Levels

[](#log-levels)

SimpleLog has eight log level severities based on [PSR Log Levels](http://www.php-fig.org/psr/psr-3/#psrlogloglevel).

```
$logger->debug('Detailed information about the application run.');
$logger->info('Informational messages about the application run.');
$logger->notice('Normal but significant events.');
$logger->warning('Information that something potentially bad has occured.');
$logger->error('Runtime error that should be monitored.');
$logger->critical('A service is unavailable or unresponsive.');
$logger->alert('The entire site is down.');
$logger->emergency('The Web site is on fire.');
```

By default all log levels are logged. The minimum log level can be changed in two ways:

- Optional constructor parameter
- Setter method at any time

```
use Psr\Log\LogLevel;

// Optional constructor Parameter (Only error and above are logged [error, critical, alert, emergency])
$logger = new SimpleLog\Logger($logfile, $channel, LogLevel::ERROR);

// Setter method (Only warning and above are logged)
$logger->setLogLevel(LogLevel::WARNING);
```

### Contextual Data

[](#contextual-data)

SimpleLog enables logging best practices to have general-use log messages with contextual support data to give context to the message.

The second argument to a log message is an associative array of key-value pairs that will log as a JSON string, serving as the contextual support data to the log message.

```
// Add context to a Web request.
$log->info('Web request initiated', ['method' => 'GET', 'endpoint' => 'user/account', 'queryParameters' => 'id=1234']);

// Add context to a disk space warning.
$log->warning('Free space is below safe threshold.', ['volume' => '/var/log', 'availablePercent' => 4]);
```

Context values can be interpolated into the log message using `{placeholder}` syntax as defined by PSR-3:

```
$logger->info('User {username} logged in from {ip}', ['username' => 'mark', 'ip' => '192.168.1.1']);
// Message output: User mark logged in from 192.168.1.1
```

The full context array is still included as JSON in the log line alongside the interpolated message.

### Logging Exceptions

[](#logging-exceptions)

Exceptions are logged with the contextual data using the key *exception* and the value the exception variable.

```
catch (\Exception $e) {
    $logger->error('Something exceptional has happened', ['exception' => $e]);
}
```

### Log Channels

[](#log-channels)

Think of channels as namespaces for log lines. If you want to have multiple loggers or applications logging to a single log file, channels are your friend.

Channels can be set in two ways:

- Constructor parameter
- Setter method at any time

```
// Constructor Parameter
$channel = 'router';
$logger  = new SimpleLog\Logger($logfile, $channel);

// Setter method
$logger->setChannel('database');
```

### Debug Features

[](#debug-features)

#### Logging to STDOUT

[](#logging-to-stdout)

When developing, you can turn on log output to the screen (STDOUT) as a convenience.

```
$logger->setStdout(true);
$logger->debug('This will get logged to STDOUT as well as the log file.');
```

#### Dummy Logger

[](#dummy-logger)

Suppose you need a logger to meet an injected dependency during a unit test, and you don't want it to actually log anything. You can set the log level to `Logger::LOG_LEVEL_NONE` which won't log at any level.

```
use SimpleLog\Logger;

$logger->setLogLevel(Logger::LOG_LEVEL_NONE);
$logger->info('This will not log to a file.');
```

Unit Tests
----------

[](#unit-tests)

```
$ cd tests
$ phpunit
```

[![Coverage Status](https://camo.githubusercontent.com/32532daefee2264eb43f01603d4c11a26f70f1a3a4bbd1d06b5f16e5af0e6281/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d61726b726f676f79736b692f73696d706c656c6f672d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/markrogoyski/simplelog-php?branch=master)

Standards
---------

[](#standards)

SimpleLog conforms to the following standards:

- PSR-1 - Basic coding standard ()
- PSR-3 - Logger Interface ()
- PSR-4 - Autoloader ()
- PSR-12 - Extended coding style guide ()

License
-------

[](#license)

SimpleLog is licensed under the MIT License.

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance85

Actively maintained with recent releases

Popularity38

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity79

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

Recently: every ~226 days

Total

11

Last Release

77d ago

Major Versions

v0.4.x-dev → v1.0.02023-09-09

v1.0.x-dev → v2.0.02024-02-25

v2.x-dev → v3.0.02026-03-03

PHP version history (4 changes)v0.1.0PHP &gt;=7.0.0

v1.0.0PHP &gt;=7.4.0

v2.0.0PHP &gt;=8.0.0

v3.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10004372?v=4)[Mark Rogoyski](/maintainers/markrogoyski)[@markrogoyski](https://github.com/markrogoyski)

---

Top Contributors

[![markrogoyski](https://avatars.githubusercontent.com/u/10004372?v=4)](https://github.com/markrogoyski "markrogoyski (73 commits)")

---

Tags

logpsr-3logginglogger

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/markrogoyski-simplelog-php/health.svg)

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

###  Alternatives

[monolog/monolog

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

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

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3451.5M24](/packages/analog-analog)[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k7](/packages/inpsyde-wonolog)[apix/log

Minimalist, thin and fast PSR-3 compliant (multi-bucket) logger.

511.0M18](/packages/apix-log)[amphp/log

Non-blocking logging for PHP based on Amp, Revolt, and Monolog.

402.6M70](/packages/amphp-log)[elastic/ecs-logging

Format and enrich your log files in the elastic common schema

21907.5k1](/packages/elastic-ecs-logging)

PHPackages © 2026

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