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

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

originphp/log
=============

OriginPHP Log

2.0.1(4y ago)112.6k↓75%9MITPHPPHP &gt;=7.3.0CI failing

Since Oct 14Pushed 4y ago1 watchersCompare

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

READMEChangelogDependencies (5)Versions (15)Used By (9)

Log
===

[](#log)

[![license](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)[![build](https://github.com/originphp/log/workflows/CI/badge.svg)](https://github.com/originphp/log/actions)[![coverage](https://camo.githubusercontent.com/a6330290714c4649ecb7198b618d15b34f13f6c82f4177a8c53057751dc93914/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6f726967696e7068702f6c6f672f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/originphp/log?branch=master)

There are 4 built in Log Engines, and it is easy to implement your own. You can use the `Log` static class or PSR-3 `Logger` class.

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

[](#installation)

To install this package

```
$ composer require originphp/log

```

- `File` - Logs messages to files
- `Console` - Displays the log messages to the console screen
- `Email` - Sends log messages via email
- `Syslog` - Recommended for production systems

First you need to configure the Log library, in your application bootstrap or configuration.

```
Log::config('default', [
    'engine' => 'File',
    'file' => '/var/www/logs/application.log'
]);
```

Then to log

```
use Origin\Log\Log;
Log::error('Something has gone wrong.');
```

This will produce something like this in `/var/www/logs/application.log`.

```
[2019-03-10 13:37:49] application ERROR: Something has gone wrong.

```

Channels
--------

[](#channels)

To group your log messages, set a channel name.

```
use Origin\Log\Log;
Log::error('Something has gone wrong.',['channel'=>'invoices']);
```

This will create a log entry like this

```
[2019-03-10 13:37:49] invoices ERROR: Something has gone wrong.

```

Placeholders
------------

[](#placeholders)

You can also use placeholders in the message.

```
Log::info('Email sent to {email}',['email'=>'donny@example.com']);
```

Adding data to messages
-----------------------

[](#adding-data-to-messages)

After placeholders any have been replaced, any remaining data will be converted to a JSON string.

```
Log::info('User registered',['username'=>'pinkpotato']);
```

Which will output like this

```
[2019-03-10 13:37:49] application INFO: User registered {"username":"pinkpotato"}

```

Log Levels
----------

[](#log-levels)

Log works with all the different levels as defined in the [RFC 5424 specifications](https://tools.ietf.org/html/rfc5424).

```
Log::emergency('system is unusable');
Log::alert('action must be taken immediately');
Log::critical('a critical condition');
Log::error('an error has occured');
Log::warning('warning low disk space');
Log::notice('normal, but significant, condition');
Log::info('informational message');
Log::debug('debug-level message');
```

Configuration
-------------

[](#configuration)

You can use a single engine or multiple engines at once, and you can also customize which levels to Log on.

### File Engine

[](#file-engine)

To configure the file engine logging

```
use Origin\Log\Log;
Log::config('file',[
    'engine' => 'File',
    'file' => '/var/www/logs/application.log',
    'size' => 10485760, // or 10MB,
    'rotate' => 3
]);
```

Options for the File Engine are:

- file: file with full path
- levels: default `[]`. If you want to restrict this configuration to only certain levels, add the levels to an array e.g. `['critical','emergency','alert']`
- channels: default `[]`. If you want to restrict this configuration to only certain channels, add the channels to an array e.g. `['invoices','payments']`
- size: number of bytes when to rotate log, or you can use MB or GB, e.g. 10MB. To disable log rotation set this to `0`.
- rotate: the number of times to rotate, if set to 0, then it will delete once it reaches that size.

### Email Engine

[](#email-engine)

To configure email logging

```
use Origin\Log\Log;
Log::config('default',[
    'engine' => 'Email',
    'to' => 'you@example.com', // string email only
    'from' => ['no-reply@example.com' => 'Web Application'] // to add a name, use an array,
    'host' => 'smtp.example.com',
    'port' => 465,
    'username' => 'demo@example.com',
    'password' => 'secret',
    'timeout' => 5,
    'ssl' => true,
    'tls' => false
]);
```

Options for the Email Engine are:

- *levels*: default `[]`. If you want to restrict this configuration to only certain levels, add the levels to an array e.g. `['critical','emergency','alert']`
- *channels*: default `[]`. If you want to restrict this configuration to only certain channels, add the channels to an array e.g. `['invoices','payments']`
- *to*: The to email address or an array with the email address and name which will be used. e.g. `you@example.com` or `['you@example.com','Tony Robbins']`.
- *from*: The from email address or an array with the email address and name which will be used. e.g. `no-reply@example.com` or `['no-reply@example.com'=>'System Notifications']`.
- *host*: this is SMTP server hostname
- *port*: port number default 25
- *username*: the username to access this SMTP server
- *password*: the password to access this SMTP server
- *ssl*: default is false, set to true if you want to connect via SSL
- *tls*: default is false, set to true if you want to enable TLS
- *timeout*: how many seconds to timeout

> You should always test your email configuration first, if an exception occurs when trying to send the email, it is caught and is not logged to prevent recursion.

### Console Engine

[](#console-engine)

[![console](console-log.png)](console-log.png)

To configure the Console Engine

```
use Origin\Log\Log;
Log::config('default',[
    'engine' => 'Console'
]);
```

Options for the Console Engine are:

- stream: default:`php://stderr` this is the stream to use
- levels: default `[]`. If you want to restrict this configuration to only certain levels, add the levels to an array e.g. `['critical','emergency','alert']`
- channels: default `[]`. If you want to restrict this configuration to only certain channels, add the channels to an array e.g. `['invoices','payments']`

### Syslog Engine

[](#syslog-engine)

You should use the Syslog engine on your production server. To configure the Syslog engine.

```
use Origin\Log\Log;
Log::config('default',[
    'engine' => 'Syslog'
]);
```

Options for the Syslog Engine are:

- levels: default `[]`. If you want to restrict this configuration to only certain levels, add the levels to an array e.g. `['critical','emergency','alert']`
- channels: default `[]`. If you want to restrict this configuration to only certain channels, add the channels to an array e.g. `['invoices','payments']`

You can also pass settings to the `openlog` command, these are `identity`,`option`,`facility`, see [openlog](https://php.net/manual/en/function.openlog.php) for more information on what these do.

Example
-------

[](#example)

Lets say you want to configure the logger to log all events in a file as normal, send critical log entires by email and create a separate log for just payments.

```
use Origin\Log\Log;
// Logs all items to file
Log::config('default',[
    'engine' => 'File',
    'file' => '/var/www/logs/master.log'
]);

// Send import log items by email
Log::config('critical-emails',[
    'engine' => 'Email',
    'to' => 'you@example.com',
    'from' => ['nobody@gmail.com' => 'Web Application'],
    'levels' => ['critical','emergency','alert'],
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'username' => 'nobody@gmail.com',
    'password' => 'secret',
    'ssl' => true,
]);

// Create a seperate log for everything from the payments channel
Log::config('payments',[
    'engine' => 'File',
    'file' => '/var/www/logs/payments.log',
    'channels' => ['payments']
]);
```

### Creating a Custom Log Engine

[](#creating-a-custom-log-engine)

To create a custom Log Engine, create the folder structure `app/Log/Engine`, and create an engine class with the method `log`.

```
namespace App\Log\Engine;

use Origin\Log\Engine\BaseEngine;

class DatabaseEngine extends BaseEngine
{
    /**
     * Setup your default config here
     *
     * @var array
     */
    protected $defaultConfig =  [];

     /**
     * This will be called when the class is constructed
     *
     * @var array
     */
    protected function initialize(array $config) : void
    {

    }

    /**
      * Logs an item
      *
      * @param string $level e.g debug, info, notice, warning, error, critical, alert, emergency.
      * @param string $message 'this is a {what}'
      * @param array $context  ['what'='string']
      * @return void
      */
    public function log(string $level, string $message, array $context = []) : void
    {
        $message = $this->format($level, $message, $context);
        // do something
    }
}
```

Then in your bootstrap configuration

```
use Origin\Log\Log;
Log::config('default',[
    'className' => 'App\Log\Engine\DabaseEngine'
]);
```

### PSR-3 Logger

[](#psr-3-logger)

The Log library uses a PSR-3 Logger that you may want to use instead of the static `Log` class.

When you create the `Logger` instance you can pass a single engine configuration, which is common when just starting on a new app.

```
use Origin\Log\Logger;
$logger = new Logger([
    'engine' => 'File',
    'file' => '/var/www/logs/master.log'
]);
```

To change the settings for an engine, or add additional engines or configurations of engines

```
$logger->config('default',[
    'engine' => 'File',
    'file' => '/var/www/logs/application.log'
]);

// Send import log items by email
$logger->config('critical-emails',[
    'engine' => 'Email',
    'to' => 'you@example.com',
    'from' => ['nobody@gmail.com' => 'Web Application'],
    'levels' => ['critical','emergency','alert'],
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'username' => 'nobody@gmail.com',
    'password' => 'secret',
    'ssl' => true
]);

// Create a seperate log for everything from the payments channel
$logger->config('payments',[
    'engine' => 'File',
    'file' => '/var/www/logs/payments.log',
    'channels' => ['payments']
]);
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community15

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

Recently: every ~98 days

Total

13

Last Release

1638d ago

Major Versions

1.2.4 → 2.0.02021-01-04

1.2.5 → 2.0.12021-11-19

PHP version history (3 changes)1.0.0PHP ^7.2.0

1.2.3PHP &gt;=7.2.0

2.0.0PHP &gt;=7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e8a821333d9c7b7bc2ad3d164d142f65cd3912dea78033d31f76b0f19ba8a0c?d=identicon)[originphp](/maintainers/originphp)

---

Top Contributors

[![jamielsharief](https://avatars.githubusercontent.com/u/20553479?v=4)](https://github.com/jamielsharief "jamielsharief (38 commits)")

---

Tags

psrlogpsr-3consoleemailfilesyslogoriginPHP

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[analog/analog

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

3451.5M24](/packages/analog-analog)[apix/log

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

511.0M18](/packages/apix-log)[markrogoyski/simplelog-php

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

2818.1k4](/packages/markrogoyski-simplelog-php)[filips123/monolog-phpmailer

PHPMailer handler for Monolog

1365.6k3](/packages/filips123-monolog-phpmailer)

PHPackages © 2026

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