All Projects → jbroadway → Analog

jbroadway / Analog

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

Projects that are alternatives of or similar to Analog

Quicklogger
Library for logging on files, console, memory, email, rest, eventlog, syslog, slack, telegram, redis, logstash, elasticsearch, influxdb, graylog, Sentry, Twilio, ide debug messages and throw events for Delphi/Firemonkey/freepascal/.NET (Windows/Linux/OSX/IOS/Android).
Stars: ✭ 137 (-56.37%)
Mutual labels:  logging, logger, syslog
Rsyslog
a Rocket-fast SYStem for LOG processing
Stars: ✭ 1,385 (+341.08%)
Mutual labels:  mongodb, logging, syslog
Bugsnag Python
Official bugsnag error monitoring and error reporting for django, flask, tornado and other python apps.
Stars: ✭ 69 (-78.03%)
Mutual labels:  monitoring, error-monitoring, errors
Docker Logger
Logs collector for docker
Stars: ✭ 126 (-59.87%)
Mutual labels:  logging, logger, syslog
Logbook
An extensible Java library for HTTP request and response logging
Stars: ✭ 822 (+161.78%)
Mutual labels:  monitoring, logging, logger
Periskop
Exception Monitoring Service
Stars: ✭ 115 (-63.38%)
Mutual labels:  monitoring, error-monitoring, errors
Exceptionless
Exceptionless server and jobs
Stars: ✭ 2,107 (+571.02%)
Mutual labels:  monitoring, logging, error-monitoring
Alerta
Alerta monitoring system
Stars: ✭ 2,031 (+546.82%)
Mutual labels:  mongodb, monitoring
Mongotail
Command line tool to log all MongoDB queries in a "tail"able way
Stars: ✭ 169 (-46.18%)
Mutual labels:  mongodb, logging
mongoose-morgan
An npm package for saving morgan log inside MongoDB
Stars: ✭ 14 (-95.54%)
Mutual labels:  error-monitoring, logger
gxlog
A concise, functional, flexible and extensible logger for go.
Stars: ✭ 65 (-79.3%)
Mutual labels:  logger, logging
kernel-syslog
📝 Kernel module that can be used as a replacement for syslog, logger or logwrapper
Stars: ✭ 37 (-88.22%)
Mutual labels:  logger, syslog
periskop
Exception Monitoring Service
Stars: ✭ 128 (-59.24%)
Mutual labels:  errors, error-monitoring
Dotnetcore
.NET 5 Nuget Packages.
Stars: ✭ 146 (-53.5%)
Mutual labels:  mongodb, logging
Bricks
A standard library for microservices.
Stars: ✭ 142 (-54.78%)
Mutual labels:  mongodb, logging
bugsnag-java
Bugsnag error reporting for Java.
Stars: ✭ 51 (-83.76%)
Mutual labels:  errors, error-monitoring
Monitaure
🔔 A server uptime monitoring progressive web application - NO LONGER MAINTAINED
Stars: ✭ 135 (-57.01%)
Mutual labels:  mongodb, monitoring
bugsnag-symfony
Bugsnag notifier for the Symfony PHP framework. Monitor and report errors in your Symfony apps.
Stars: ✭ 42 (-86.62%)
Mutual labels:  errors, error-monitoring
Sysmon Config
Sysmon configuration file template with default high-quality event tracing
Stars: ✭ 3,287 (+946.82%)
Mutual labels:  monitoring, logging
Pygogo
A Python logging library with superpowers
Stars: ✭ 265 (-15.61%)
Mutual labels:  logging, logger

Analog - Minimal PHP logging library

  • Copyright: (c) 2012-Present Johnny Broadway
  • License: MIT

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].