PHPackages                             samayo/autolog - 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. samayo/autolog

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

samayo/autolog
==============

A simple PHP logger library

0.1.3(8y ago)71523MITPHPPHP &gt;=5.4.0

Since Jun 28Pushed 6y ago2 watchersCompare

[ Source](https://github.com/samayo/Autolog)[ Packagist](https://packagist.org/packages/samayo/autolog)[ Docs](http://github.com/samayo/autolog)[ RSS](/packages/samayo-autolog/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (1)Versions (6)Used By (0)

Autolog
-------

[](#autolog)

A PHP class to save/log/mail errors/notifications from your app or from `/var/log/` as they appear.

Install
-------

[](#install)

Using git

```
$ git clone https://github.com/samayo/autolog.git
```

Using composer

```
$ composer require samayo/autolog
```

Usage
-----

[](#usage)

#### Short Example.

[](#short-example)

To quickly email a user activity log

```
require __DIR__ . "/src/Logger.php";

$log = new Autolog\Logger(["email" => "user@domain.tld"]);

if($comment){
   $log->log("$user just commented \n $comment", $log::INFO, $log::EMAIL);
}
```

The `$log->log()` method accepts 4 arguments, but only the first `$msg` is required.

```
/**
 * $msg (required) the actual content to send/log
 * $type (optional) the message type: error, info, notification..
 * $handler (optional) where to send it (db, email, file log)
 * $verbosity (optional) log as simple or verbose info
 */
log($msg, $type, $handler, $verbosity);
```

Available log types, handlers, and verbosity

```
$type::INFO; // for simple tasks
$type::ERROR; // for errors ex: 404 ..
$type::ALERT; // for fatal errors or suspicious activity

$handler::EMAIL; // send to email
$handler::FILE; // write to file
$handler::DATABASE; // insert to database
$handler::SMS; // send to sms (not yet implemented)

$verbosity::SIMPLE; // send simplified log
$verbosity::VERBOSE; // send every log information

// the below will log an error, in verbose format and mail it
$log = new Autolog\Logger(["email" => "user@domain.tld"]);
$log->log($msg, $log::ERROR, $log::EMAIL, $log::VERBOSE);
```

By passing only the first arg: `$log->log($msg)` the log will tread as `ERROR`, `EMAIL`, `VERBOSE`

Examples
--------

[](#examples)

#### Sending logs to your email

[](#sending-logs-to-your-email)

```
$log = new Autolog\Logger;
$log["email"] = "user@domain.tld"; // add email

// or add your email list this:
$log = new Autolog\Logger(["email" => "user@domain.tld"]);

// then log it!
if($something){
   $log->log("something"); // email 'something'
}
```

#### Logging to file

[](#logging-to-file)

To log to a file, you need to pass a writable file to `error.log`

```
$log = new Autolog\Logger(["error.log" => __DIR__ . "/mylogs.txt"]);
$log->log("ERROR: $error", $log::INFO, $log::FILE); // don't forget $log::FILE
```

#### Inserting to database

[](#inserting-to-database)

To store your logs in a database, create a db with these schema

```
--- database name can be anything, but table and columns should be as seen below
CREATE DATABASE IF NOT EXISTS autolog;
USE autolog;
CREATE TABLE `logs` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `time` DATETIME DEFAULT NULL,
  `subject` VARCHAR(255) DEFAULT NULL,
  `level` VARCHAR(50) DEFAULT NULL,
  `message` TEXT,
  PRIMARY KEY (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4
```

Then log your info/error after calling the `pdo()` PDO object

```
$log = new Autolog\Logger;
$log->pdo(new \PDO(
   // your pdo host, db, pass here
));
$log->log("simple log", $log::ERROR, $log::DATABASE);
```

#### Method chaining

[](#method-chaining)

You can even quickly chain methods as:

```
(new \Autolog\Logger)
   ->pdo(new PDO(/**/))->log("user: $user modified his/her profile", $log::INFO, $log::DATABASE);
```

#### Handling Exceptions/Errors

[](#handling-exceptionserrors)

To log all your exceptions/errors use example below:

```
$logger = Autolog\Logger(["email" => "user@example.com"]);

// mail all thrown exceptions
set_exception_handler(function($e) use($logger){
   $logger->log($e, $log::ERROR, $log::EMAIL);
});

// mail all errors
set_error_handler(function($no, $str, $file, $line) use ($logger){
   $logger->log("Your site has error: $str in file $file at line $line", $log::ERROR, $log::EMAIL);
})
```

#### Autologs `(via cronjob)`

[](#autologs-via-cronjob)

To automatically detect log file changes and log messages, use `watch()` method.

```
// always watch new errors that appear in (nginx, php) log files
$log->watch(true);
```

To watch new logs and get notified, place the `watch()` method in it's own file like: `log_mailer.php`

```
// log_mailer.php
require __DIR__ . "/src/Logger.php";
(new Autolog\Logger([
  "nginx.log"  => "/var/log/nginx/error.log",
  "php-fpm.log"  => "/var/log/php-fpm/error.log",
  "mariadb.log" => "/var/log/mariadb/mariadb.log",
  "access.log"  => "access.txt",
  "email"  => "user@example.com"
]))->watch(true);
```

Now, you can set a cronjob that executes the above script every min/hour then you'll get a new mail everytime a new error is logged in /var/log/...

It is important give the `access.log` a file where the last time like: nginx.log is accessed. This is because to detect new error, you must store the timestamp of the last time we check nginx.log So, if the mtime for nginx file is not the same as we have stored, it means a new log is found ~

#### License: MIT

[](#license-mit)

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

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

Total

4

Last Release

3207d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8224efc6c85f9ed635239195b886766f000c05d279ba93124dcc361c235efdf7?d=identicon)[samayo](/maintainers/samayo)

---

Top Contributors

[![samayo](https://avatars.githubusercontent.com/u/5304093?v=4)](https://github.com/samayo "samayo (31 commits)")

---

Tags

errorlognotificationlogerrornotification

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/samayo-autolog/health.svg)

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

###  Alternatives

[analog/analog

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

3511.6M24](/packages/analog-analog)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

419662.2k5](/packages/yadahan-laravel-authentication-log)[saasscaleup/laravel-log-alarm

Laravel log Alarm help you to set up alarm when errors occur in your system and send you a notification via Slack and email

26927.9k](/packages/saasscaleup-laravel-log-alarm)[guanguans/laravel-exception-notify

Monitor exception and report to the notification channels(Log、Mail、AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

14844.4k1](/packages/guanguans-laravel-exception-notify)[larabug/larabug

Laravel 6.x/7.x/8.x/9.x/10.x/11.x/12.x/13.x bug notifier

299571.0k1](/packages/larabug-larabug)[baibaratsky/yii2-rollbar

Rollbar for Yii2

35131.9k](/packages/baibaratsky-yii2-rollbar)

PHPackages © 2026

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