2017 © Pedro Peláez
 

library analog

PHP logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

image

analog/analog

PHP logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  • Sunday, September 17, 2017
  • by jbroadway
  • Repository
  • 27 Watchers
  • 263 Stars
  • 362,435 Installations
  • PHP
  • 34 Dependents
  • 0 Suggesters
  • 31 Forks
  • 2 Open issues
  • 11 Versions
  • 12 % Grown

The README.md

Analog - Minimal PHP logging library

GitHub Workflow Status GitHub Packagist Version Packagist PHP Version Support Packagist Downloads, (*1)

A minimal PHP logging package based on the idea of using closures for configurability and extensibility. It functions as a static class, but you can completely control the writing of log messages through a closure function (aka anonymous functions), or use the Analog\Logger wrapper that implements the PSR-3 specification., (*2)

Installation

Install the latest version with:, (*3)

$ composer require analog/analog

Usage

Basic Usage

<?php

use Analog\Analog;
use Analog\Handler\FirePHP;

Analog::handler (FirePHP::init ());

Analog::log ('Take me to your browser');

Usage with PSR-3

<?php

use Analog\Logger;
use Analog\Handler\Variable;

$logger = new Logger;

$log = '';

$logger->handler (Variable::init ($log));

$logger->alert ('Things are really happening right now!');

// With context
$logger->debug ('Testing {0}:{1}', [__FILE__, __LINE__]);

var_dump ($log);

Usage with a custom handler

<?php

use Analog\Analog;

// Default logging to /tmp/analog.txt
Analog::log ('Log this error');

// Log to a MongoDB log collection
Analog::handler (function ($info) {
    static $conn = null;
    if (! $conn) {
        $conn = new Mongo ('localhost:27017');
    }
    $conn->mydb->log->insert ($info);
});

// Log an alert
Analog::log ('The sky is falling!', Analog::ALERT);

// Log some debug info
Analog::log ('Debugging info', Analog::DEBUG);

Usage without composer

Analog uses a simple autoloader internally, so if you don't have access to composer you can clone this repository and include it like this:, (*4)

<?php

require 'analog/lib/Analog.php';

Analog::handler (Analog\Handler\Stderr::init ());

Analog::log ('Output to php://stderr');

For more examples, see the examples folder., (*5)

Logging Options

By default, this class will write to a file named sys_get_temp_dir() . '/analog.txt' using the format "machine - date - level - message\n", making it usable with no customization necessary., (*6)

Analog also comes with dozens of pre-written handlers in the Analog/Handlers folder, with examples for each in the examples folder. These include:, (*7)

  • Amon - Send logs to the Amon server monitoring tool
  • Apprise - Send notifications through the apprise command line tool
  • Buffer - Buffer messages to send all at once (works with File, Mail, Stderr, and Variable handlers)
  • ChromeLogger - Sends messages to Chrome Logger browser plugin
  • EchoConsole - Echo output directly to the console
  • File - Append messages to a file
  • FirePHP - Send messages to FirePHP browser plugin
  • GELF - Send message to the Graylog2 log management server
  • IFTTT - Trigger webhooks via the IFTTT service
  • Ignore - Do nothing
  • LevelBuffer - Buffer messages and send only if sufficient error level reached
  • LevelName - Convert log level numbers to names in log output
  • Mail - Send email notices
  • Mongo - Save to MongoDB collection
  • Multi - Send different log levels to different handlers
  • PDO - Send messages to any PDO database connection (MySQL, SQLite, PostgreSQL, etc.)
  • Post - Send messages over HTTP POST to another machine
  • Redis - Save messages to Redis key using RPUSH
  • Slackbot - Post messages to Slack via Slackbot
  • Stderr - Send messages to STDERR
  • Syslog - Send messages to syslog
  • Threshold - Only writes log messages above a certain threshold
  • Variable - Buffer messages to a variable reference
  • WPMail - Send email notices using Wordpress wp_mail()

So while it's a micro class, it's highly extensible and very capable out of the box too., (*8)

Rationale

I wrote this because I wanted something very small and simple like KLogger, and preferably not torn out of a wider framework if possible. After searching, I wasn't happy with the single-purpose libraries I found. With KLogger for example, I didn't want an object instance but rather a static class, and I wanted more flexibility in the back-end., (*9)

I also found some that had the flexibility also had more complexity, for example Monolog is dozens of source files (not incl. tests). With closures, this seemed to be a good balance of small without sacrificing flexibility., (*10)

What about Analog, the logfile analyzer? Well, since it hasn't been updated since 2004, I think it's safe to call a single-file PHP logging class the same thing without it being considered stepping on toes :), (*11)

The Versions

17/09 2017

dev-master

9999999-dev https://github.com/jbroadway/analog

PHP logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

17/09 2017

1.0.10-stable

1.0.10.0 https://github.com/jbroadway/analog

PHP logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

17/11 2016

1.0.9-stable

1.0.9.0 https://github.com/jbroadway/analog

PHP 5.3+ micro logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

11/08 2016

1.0.8-stable

1.0.8.0 https://github.com/jbroadway/analog

PHP 5.3+ micro logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

25/05 2015

1.0.7-stable

1.0.7.0 https://github.com/jbroadway/analog

PHP 5.3+ micro logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

13/02 2015

1.0.6-stable

1.0.6.0 https://github.com/jbroadway/analog

PHP 5.3+ micro logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

13/02 2015

1.0.5-stable

1.0.5.0 https://github.com/jbroadway/analog

PHP 5.3+ micro logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

24/01 2014

1.0.4-stable

1.0.4.0 https://github.com/jbroadway/analog

PHP 5.3+ micro logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

22/04 2013

1.0.3-stable

1.0.3.0 https://github.com/jbroadway/analog

PHP 5.3+ micro logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

01/03 2013

1.0.2-stable

1.0.2.0 https://github.com/jbroadway/analog

PHP 5.3+ micro logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts

25/02 2013

1.0.1-stable

1.0.1.0 https://github.com/jbroadway/analog

PHP 5.3+ micro logging class that can be extended via closures. Includes several pre-built handlers including file, mail, syslog, HTTP post, and MongoDB.

  Sources   Download

MIT

The Requires

 

debug logger log logging error debugging syslog alerts