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

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

popphp/pop-log
==============

Pop Log Component for Pop PHP Framework

4.0.4(6mo ago)48.9k↑38.9%12BSD-3-ClausePHPPHP &gt;=8.3.0CI passing

Since Jul 16Pushed 6mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (28)Used By (2)

pop-log
=======

[](#pop-log)

[![Build Status](https://github.com/popphp/pop-log/workflows/phpunit/badge.svg)](https://github.com/popphp/pop-log/actions)[![Coverage Status](https://camo.githubusercontent.com/44b74ae687fee6a491bd37764fda9cda3ecfa4589d9b4b53409c42ddd4947c49/687474703a2f2f63632e706f707068702e6f72672f636f7665726167652e7068703f636f6d703d706f702d6c6f67)](http://cc.popphp.org/pop-log/)

[![Join the chat at https://discord.gg/TZjgT74U7E](https://camo.githubusercontent.com/acad7b0eeb78b78d08ffd2b85681ab243436388b5f86f8bcb956a69246e53739/68747470733a2f2f6d656469612e706f707068702e6f72672f696d672f646973636f72642e737667)](https://discord.gg/TZjgT74U7E)

- [Overview](#overview)
- [Install](#install)
- [Quickstart](#quickstart)
- [Writers](#writers)
    - [File](#file)
    - [Mail](#mail)
    - [Database](#database)
    - [HTTP](#http)
- [Context](#context)
- [Limits](#limits)

Overview
--------

[](#overview)

`pop-log` is a logging component that provides a way of logging events following the standard BSD syslog protocol outlined in [RFC-3164](http://tools.ietf.org/html/rfc3164). Support is built-in for writing log messages to a file or database table or deploying them via email or HTTP. The eight available log message severity values are:

- EMERG (0)
- ALERT (1)
- CRIT (2)
- ERR (3)
- WARN (4)
- NOTICE (5)
- INFO (6)
- DEBUG (7)

and are available via their respective methods:

- $log-&gt;emergency($message);
- $log-&gt;alert($message);
- $log-&gt;critical($message);
- $log-&gt;error($message);
- $log-&gt;warning($message);
- $log-&gt;notice($message);
- $log-&gt;info($message);
- $log-&gt;debug($message);

`pop-log` is a component of the [Pop PHP Framework](https://www.popphp.org/).

[Top](#pop-log)

Install
-------

[](#install)

Install `pop-log` using Composer.

```
composer require popphp/pop-log

```

Or, require it in your composer.json file

```
"require": {
    "popphp/pop-log" : "^4.0.4"
}

```

[Top](#pop-log)

Quickstart
----------

[](#quickstart)

This is a basic example using the file writer:

```
use Pop\Log\Logger;
use Pop\Log\Writer\File;

$log = new Logger(new File(__DIR__ . '/logs/app.log'));

$log->info('Just a info message');
$log->alert('Look Out! Something serious happened!');
```

Then, your 'app.log' file will contain:

```
2015-07-11 12:32:32    6    INFO    Just a info message
2015-07-11 12:32:33    1    ALERT   Look Out! Something serious happened!

```

[Top](#pop-log)

Writers
-------

[](#writers)

There are four available log writers, but others can be created if they implement the `Pop\Log\Writer\WriterInterface`.

### File

[](#file)

The file log writer simply stores the log output to a log file on disk. The log file format is derived from the log filename. Supported log file types include:

- Plain text (`.log` or `.txt`)
- CSV (`.csv`)
- TSV (`.tsv`)
- XML (`.xml`)
- JSON (`.json`)

```
use Pop\Log\Logger;
use Pop\Log\Writer\File;

$log = new Logger(new File(__DIR__ . '/logs/app.csv'));

$context = [
    'name'      => 'my-log-entry',
    'timestamp' => date('Y-m-d H:i:s')
];

$log->info('Just a info message', $context);
```

The above code creates a CSV file with the log entry:

```
2023-10-31 15:58:28,6,my-log-entry,"Just a info message",
```

[Top](#pop-log)

### Mail

[](#mail)

The mail log writer sends the log entries via email using the `popphp/pop-mail` component. The constructor requires a `Pop\Mail\Mailer` object and at least one email as the second argument. An optional third argument allows you to pass in additional email headers, like a subject and CC addresses.

```
use Pop\Log\Logger;
use Pop\Log\Writer\Mail;
use Pop\Mail\Mailer;
use Pop\Mail\Transport\Sendmail;

$emails  = ['sysadmin@mydomain.com', 'logs@mydomain.com'];
$options = [
    'subject' => 'Custom Log Entry:',
    'cc'      => 'another@mydomain.com'
];

$mailer = new Mailer(new Sendmail());
$log    = new Logger(new Mail($mailer, $emails, $options));

$log->info('Just a info message');
$log->alert('Look Out! Something serious happened!');
```

Then the emails listed above will receive a series of emails like this:

```
Subject: Custom Log Entry: INFO (6)
2023-11-11 12:32:32    6    INFO    Just a info message

```

```
Subject: Custom Log Entry: ALERT (1)
2023-11-11 12:32:33    1    ALERT   Look Out! Something serious happened!

```

[Top](#pop-log)

### Database

[](#database)

Writing a log to a table in a database requires the `popphp/pop-db` component. The database writer constructor takes an instance of `Pop\Db\Adapter\AbstractAdapter`and also an optional `$table` argument (the default table name is `pop_log`).

```
use Pop\Db\Db;
use Pop\Log\Logger;
use Pop\Log\Writer\Database;

$db  = Db::connect('sqlite', __DIR__ . '/logs/.htapplog.sqlite');
$log = new Logger(new Database($db, 'system_logs'));

$log->info('Just a info message');
$log->alert('Look Out! Something serious happened!');
```

In this case, the logs are written to a database table that has the columns `id`, `timestamp`, `level`, `name` and `message`. So, after the example above, your database table would look like this:

IdTimestampLevelNameMessage12015-07-11 12:32:326INFOJust a info message22015-07-11 12:32:331ALERTLook Out! Something serious happened![Top](#pop-log)

### HTTP

[](#http)

Using the HTTP writer requires the `pop-http` component. It creates a request and sends it to the HTTP logging resource. (Refer to the `pop-http` documentation for more information on how to use the HTTP client.)

```
use Pop\Log\Logger;
use Pop\Log\Writer;
use Pop\Http\Client;
use Pop\Http\Auth;

$client = new Client(
    'https://logs.mydomain.com/',
    ['method' => 'POST'],
    Auth::createKey('LOG_API_KEY')
);

$log = new Logger(new Writer\Http($client);
$log->info('Just a info message');
$log->alert('Look Out! Something serious happened!');
```

The log writer will send HTTP requests with the log data to the HTTP service with the following HTTP data fields:

- `timestamp`
- `level`
- `name`
- `message`
- `context`

[Top](#pop-log)

Context
-------

[](#context)

For additional contextual information, the `$context` array can be passed to the methods called to trigger the log entry. It can contain:

```
$context = [
    'name'      => 'my-log-entry',
    'timestamp' => date('Y-m-d H:i:s'),
    'format'    => 'json'
];
```

```
use Pop\Log\Logger;
use Pop\Log\Writer\File;

$log = new Logger(new File(__DIR__ . '/logs/app.log'));

$context = [
    'name'      => 'my-log-entry',
    'timestamp' => date('Y-m-d H:i:s')
];

$log->info('Just a info message', $context);
```

[Top](#pop-log)

Limits
------

[](#limits)

Log level limits can be set for the log writer objects to enforce the severity of which log messages actually get logged:

```
use Pop\Log\Logger;
use Pop\Log\Writer\File;

$prodLog = new File(__DIR__ . '/logs/app_prod.log');
$devLog  = new File(__DIR__ . '/logs/app_dev.log');

$prodLog->setLogLimit(3); // Log only ERROR (3) and above
$devLog->setLogLimit(6);  // Log only INFO (6) and above

$log = new Logger([$prodLog, $devLog]);

$log->alert('Look Out! Something serious happened!'); // Will write to both writers
$log->info('Just a info message');                    // Will write to only app_dev.log
```

The `app_prod.log` file will contain:

```
2023-11-11 12:32:33    1    ALERT   Look Out! Something serious happened!

```

And the `app_dev.log` file will contain:

```
2023-11-11 12:32:33    1    ALERT   Look Out! Something serious happened!
2023-11-11 12:32:34    6    INFO    Just a info message

```

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance67

Regular maintenance activity

Popularity29

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 98.6% 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 ~171 days

Total

23

Last Release

196d ago

Major Versions

2.2.0 → 3.0.02017-02-22

v2.x-dev → 3.0.32019-01-10

3.3.2 → 4.0.02023-12-18

PHP version history (8 changes)2.0.0PHP &gt;=5.4.0

3.0.0PHP &gt;=5.6.0

3.0.3PHP &gt;=7.1.0

3.3.0PHP &gt;=7.3.0

3.3.1PHP &gt;=7.4.0

4.0.0PHP &gt;=8.1.0

4.0.2PHP &gt;=8.2.0

4.0.4PHP &gt;=8.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c19dee900e9e20039c723cc403f76b5c22ac2dddb3f86773ae64fb082d4949e2?d=identicon)[nicksagona](/maintainers/nicksagona)

---

Top Contributors

[![nicksagona](https://avatars.githubusercontent.com/u/898670?v=4)](https://github.com/nicksagona "nicksagona (73 commits)")[![magikstm](https://avatars.githubusercontent.com/u/24783458?v=4)](https://github.com/magikstm "magikstm (1 commits)")

---

Tags

logphploggingsyslogpoppop php

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[analog/analog

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

3451.5M24](/packages/analog-analog)[hedii/laravel-gelf-logger

A Laravel package to send logs to a gelf compatible backend like graylog

1333.4M10](/packages/hedii-laravel-gelf-logger)[logtail/monolog-logtail

Logtail handler for Monolog

233.2M3](/packages/logtail-monolog-logtail)

PHPackages © 2026

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