• Stars
    star
    342
  • Rank 123,697 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 13 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP logging library that is highly extendable and simple to use.

Analog - Minimal PHP logging library

GitHub Workflow Status GitHub Packagist Version Packagist PHP Version Support Packagist Downloads

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.

Installation

Install the latest version with:

$ 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!');

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:

<?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.

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.

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

  • 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.

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.

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.

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 :)

More Repositories

1

urlify

A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.
PHP
673
star
2

elefant

Elefant, the refreshingly simple PHP CMS and web framework.
PHP
209
star
3

phpactiveresource

A PHP client library for easily accessing Ruby on Rails-based REST services
PHP
116
star
4

cacophony

Cacophony HTML5 Interactive Video Player
JavaScript
40
star
5

slimdown

A simple regex-based Markdown parser in PHP.
PHP
32
star
6

sitellite

Sitellite Web Content Management System (CMS)
PHP
22
star
7

hypester

A JavaScript library to help with common forms of interactivity in the Tumult Hype HTML5 editor.
JavaScript
11
star
8

pubmail

Basic PHP5/SQLite mailing list/email newsletter software for bands.
PHP
10
star
9

form

Form builder app for the Elefant CMS
PHP
10
star
10

scorm

Adds SCORM support to the Elefant CMS.
JavaScript
9
star
11

template-bench

Benchmark of Elefant's template engine against Twig templates
PHP
9
star
12

phpmark

A fork of phpmark to add newer frameworks
PHP
7
star
13

php-dbal-bench

A benchmark of several PHP database abstraction layers.
PHP
7
star
14

first-wave-alien-recon

You are a UFO from an alien civilization sent on a reconnaissance mission to learn about a planet called Earth, and its dominant species, who call themselves humans.
C#
7
star
15

au

Easy audio manipulation on the command line.
PHP
6
star
16

assetic

Javascript/CSS optimizer for the Elefant CMS, powered by Assetic
PHP
6
star
17

bootstrapped

A theme for the Elefant CMS powered by the Twitter Bootstrap CSS framework.
5
star
18

lemur

Lemur Learning, an e-learning app for the Elefant CMS.
JavaScript
5
star
19

router.js

A simple client-side request router to be used in conjunction with History.js and jQuery.
JavaScript
5
star
20

bench

A single-method PHP 5.3+ benchmarking utility
PHP
4
star
21

sitemaps

Google Sitemaps generator for the Elefant CMS
PHP
4
star
22

siteforge

SiteForge Collaborative Development Platform
PHP
4
star
23

wires

Auto-connects Alpine.js to Elefant CMS handlers for easier single-page app development (based on Laravel Livewire)
PHP
4
star
24

saasy

Elefant app that provides the glue for building custom SaaS services with Bootstrap theme support.
JavaScript
4
star
25

menubuilder

A menu builder app for the Elefant CMS using YAML files to define menus.
PHP
4
star
26

wiki

Wiki app for the Elefant CMS
PHP
4
star
27

elefant-vagrant

Virtual Machines for Elefant Development using Vagrant + Chef
PHP
4
star
28

visor

API documentation generator for the Elefant CMS
PHP
4
star
29

search

Search app for the Elefant CMS, powered by ElasticSearch or IndexTank
PHP
3
star
30

phpmark-elefant

Fork of phpmark to benchmark the Elefant web framework
PHP
3
star
31

events

Events calendar app for the Elefant CMS
JavaScript
3
star
32

dbman

Database manager app for the Elefant CMS
PHP
3
star
33

distinctelements

A pure PHP implementation of the Distinct Elements in Streams algorithm for estimating the number of distinct elements in a set.
PHP
3
star
34

analytics

Google Analytics app for the Elefant CMS.
JavaScript
3
star
35

asl-player

A sign language video player for Apache Cordova that embeds into the corner of your screen, allowing for simultaneous playback with another video.
Objective-C
3
star
36

videojs

Video.js player for the Elefant CMS
PHP
2
star
37

githubfetcher

PHP 5.3+ GitHub project fetching class
PHP
2
star
38

filepicker

Filepicker.io helper app for the Elefant CMS.
PHP
2
star
39

products

Simple shopping cart for the Elefant CMS
JavaScript
2
star
40

elefant-quickstart

Elefant quickstart for Pagoda Box
PHP
2
star
41

cloudfront

CloudFront integration for the Elefant CMS
PHP
2
star
42

lists

A simple Elefant CMS app for keeping track of lists of site members.
PHP
2
star
43

desktop

Sitellite Desktop, an Adobe AIR app for interacting with the Sitellite CMS.
JavaScript
2
star
44

pdf

Embedded PDF viewer for the Elefant CMS, based on PDF.js
Java
2
star
45

stripe

Stripe payments integration for the Elefant CMS
JavaScript
2
star
46

resque

PHP-Resque integration for the Elefant CMS
PHP
2
star
47

elefant-docs

Elefant CMS documentation project.
CSS
2
star
48

php-mail-test

Memory usage test for various PHP mail libraries
PHP
2
star
49

band-o-matic

Software for making beautiful mobile (iPhone/iPad) websites for bands.
PHP
2
star
50

faq

FAQ app for the Elefant CMS
PHP
2
star
51

polls

Native polling app for ElefantCMS
PHP
2
star
52

saas

SaaS helpers for the Elefant PHP web framework
PHP
2
star
53

galleries

Photo gallery app for the Elefant CMS
PHP
2
star
54

ansible-plasticscm

An Ansible role for installing Plastic SCM.
Ruby
2
star
55

galleries_old

Photo gallery creation app for the Elefant CMS
PHP
2
star
56

theme_installer

Composer.phar installer for Elefant CMS themes.
PHP
2
star
57

lorem

Lorem ipsum generator for the Elefant CMS.
PHP
1
star
58

boris

Boris REPL for the Elefant CMS
PHP
1
star
59

simplement

Simplement Theme for Elefant CMS
1
star
60

montreal

Montreal Theme for Elefant CMS
1
star
61

chat

Member chat box for the Elefant CMS
PHP
1
star
62

themebrowser

Theme browser app for elefantcms.com
PHP
1
star
63

washi

Washi Theme for Elefant CMS
1
star
64

subtlesquared

SubtleSquared Theme for Elefant CMS
1
star
65

httpshell

HTTP request testing tool as an Elefant add-on
PHP
1
star
66

installtest

Install/upgrade test app for Elefant CMS
PHP
1
star
67

elefant-updates

Update files (patches and scripts) for the Elefant CMS.
Shell
1
star
68

bigtype

BigType Theme for Elefant CMS
1
star
69

loginradius

Social login app for the Elefant CMS, powered by LoginRadius
PHP
1
star
70

organizations

A simple Elefant CMS app for keeping track of organizations site members belong to.
PHP
1
star
71

elefant_bbedit_clippings

BBEdit clippings set for the Elefant PHP framework.
PHP
1
star
72

chef-elefant

A chef recipe for installing the Elefant CMS on a basic LAMP stack.
Ruby
1
star
73

elefant_installer

Composer.phar installer for Elefant CMS apps.
PHP
1
star
74

comments

A reusable, embeddable comments component for the Elefant CMS.
PHP
1
star
75

bluesatellite

Blue Satellite theme for the Elefant CMS
1
star
76

raleway

Raleway-based theme for the Elefant CMS
1
star
77

literati

Literati theme for the Elefant CMS
1
star
78

courses

Course builder and delivery app for the Elefant CMS.
JavaScript
1
star
79

swiftsearch

Swiftype search service integration for the Elefant CMS.
PHP
1
star
80

docusaur

API documentation browser for software projects, written as an Elefant CMS app.
PHP
1
star
81

listings

Listings for the new Elefant CMS website.
PHP
1
star
82

inflicted

Inflicted Theme for the Elefant CMS
1
star
83

elefant_sublime_snippets

Sublime Text snippets for the Elefant PHP framework.
1
star
84

migrate

Database Migrations for the Elefant CMS
PHP
1
star
85

docs

Documentation app for the Elefant CMS.
PHP
1
star
86

storyteller-user-manual

Storyteller LMS - User Manual
1
star
87

appbrowser

App browser for elefantcms.com
PHP
1
star
88

contacts

Sample app for building CRUD actions in the Elefant web framework.
PHP
1
star
89

typekit

Typekit app for the Elefant CMS
PHP
1
star
90

todos

Todos example app integrating the Elefant CMS and Backbone.js, based on the Backbone.js Todos example app.
JavaScript
1
star
91

elefant_textmate_bundle

TextMate bundle for the Elefant PHP framework.
1
star
92

githubfetcher_test

An empty project repo for testing my GithubFetcher PHP class.
1
star