/** * @depends test_format */ function test_handler() { // Test logging using a closure Analog::handler(function ($msg) { AnalogTest::$log .= vsprintf(Analog::$format, $msg); }); Analog::log('Testing'); $this->assertStringMatchesFormat("localhost, %d-%d-%d %d:%d:%d, 3, Testing\n", self::$log); }
/** * @depends test_format */ function test_handler() { // Test logging using a closure Analog::handler(function ($msg) { AnalogTest::$log .= vsprintf(Analog::$format, $msg); }); Analog::log('Testing'); $this->assertEquals(sprintf("%s, %s, %d, %s\n", 'localhost', gmdate('Y-m-d H:i:s'), 3, 'Testing'), self::$log); }
public function __construct() { if (!file_exists("./log_files")) { mkdir('./log_files'); } $this->log_file = "./log_files/Log.txt"; if (file_exists($this->log_file)) { if (filesize($this->log_file) >= MD_LOG_FILE_SIZE) { unlink($this->log_file); } } Analog::handler(Analog\Handler\File::init($this->log_file)); }
public function __construct() { $this->path = MD_ROOT . "/log_files"; if (!file_exists($this->path)) { mkdir($this->path); } $this->log_file = $this->path . "/ErrorLog.txt"; if (file_exists($this->log_file)) { if (filesize($this->log_file) >= MD_LOG_FILE_SIZE) { unlink($this->log_file); } } Analog::handler(Analog\Handler\File::init($this->log_file)); }
public function __construct($message = null, $code = 0) { if (!file_exists("./log_files")) { mkdir('./log_files'); } $this->log_file = './log_files/Log.txt'; if (!$message) { throw new $this('Unknown ' . get_class($this)); } Analog::handler(Analog\Handler\File::init($this->log_file)); parent::__construct($message, $code); Analog::log($this->__toString(), Analog::ERROR); $handleFilesFolder = new HandleFilesFolder(); $handleFilesFolder->handle(); if (file_exists("FTP_SEMAMPHORE.smph")) { unlink("FTP_SEMAMPHORE.smph"); } }
public function __construct($message = "Unknown error", $code = 0) { if (!file_exists(MD_LOG_FILE_DIR)) { mkdir(MD_LOG_FILE_DIR); } $this->log_file = MD_LOG_FILE_DIR . '/Log.txt'; if (!$message) { throw new $this('Unknown ' . get_class($this)); } Analog::handler(Analog\Handler\File::init($this->log_file)); if (gettype($message) !== "string") { $message = "Unknown error"; } parent::__construct($message, 10); Analog::log($this->__toString(), Analog::ERROR); $handleFilesFolder = new HandleFilesFolder(); $handleFilesFolder->handle(); if (file_exists(MD_ROOT . "/FTP_SEMAMPHORE.smph")) { unlink(MD_ROOT . "/FTP_SEMAMPHORE.smph"); } }
<?php require '../lib/Analog.php'; Analog::handler(Analog\Handler\Mongo::init('localhost:27017', 'testing', 'log')); Analog::log('Error message'); Analog::log('Debug info', Analog::DEBUG); $m = new Mongo('localhost:27017'); $cur = $m->testing->log->find(); foreach ($cur as $doc) { print_r($doc); } $m->testing->log->remove();
<?php require '../lib/Analog.php'; $log = ''; Analog::handler(Analog\Handler\Post::init('http://localhost:8080/')); Analog::log('foo'); Analog::log('bar'); echo $log;
<?php require '../lib/Analog.php'; $log = ''; Analog::handler(Analog\Handler\Threshold::init(Analog\Handler\Variable::init($log), Analog::ERROR)); // these will be ignored Analog::log('Debugging...', Analog::DEBUG); Analog::log('Minor warning...', Analog::WARNING); echo "Log is still empty:\n" . $log . "\n"; // but these will be logged Analog::log('An error...', Analog::ERROR); Analog::log('Oh noes!', Analog::URGENT); echo "Log now has everything:\n" . $log;
<?php require '../lib/Analog.php'; Analog::handler(Analog\Handler\Ignore::init()); Analog::log('Hellooooooo');
<?php require '../lib/Analog.php'; Analog::handler(Analog\Handler\Stderr::init()); Analog::log('Output to php://stderr');
<?php require '../lib/Analog.php'; Analog::log('foo'); Analog::log('bar'); echo file_get_contents(Analog::handler()); unlink(Analog::handler());
<?php require '../lib/Analog.php'; Analog::handler(Analog\Handler\ChromeLogger::init()); // debug-level message Analog::debug($_SERVER); // an info message Analog::info('An error message'); // a warning message Analog::warning('Turn back before it\'s too late'); // an error with no file/line #'s Analog::log('Another error message');
<?php // 1. Install the GELF classes from https://github.com/Graylog2/gelf-php require 'GELFMessage.php'; require 'GELFMessagePublisher.php'; require '../lib/Analog.php'; Analog::handler(Analog\Handler\GELF::init('localhost')); Analog::log('Error message'); Analog::log(array('Debug info', __FILE__, __LINE__), Analog::DEBUG);
<?php require '../lib/Analog.php'; Analog::handler(Analog\Handler\Buffer::init(Analog\Handler\Mail::init('*****@*****.**', 'Log messages', '*****@*****.**'))); // will all be sent as one email instead of three Analog::log('Message one'); Analog::log('Message two'); Analog::log('Message three');
<?php require '../lib/Analog.php'; $errors = "Errors:\n"; $warnings = "Warnings:\n"; $debug = "Debug:\n"; Analog::handler(Analog\Handler\Multi::init(array(Analog::ERROR => Analog\Handler\Variable::init($errors), Analog::WARNING => Analog\Handler\Variable::init($warnings), Analog::DEBUG => Analog\Handler\Variable::init($debug)))); Analog::log('First error'); Analog::log('Emergency!', Analog::URGENT); Analog::log('A warning...', Analog::WARNING); Analog::log('Some info', Analog::INFO); Analog::log('Debugging output', Analog::DEBUG); echo $errors; echo "-----\n"; echo $warnings; echo "-----\n"; echo $debug;
<?php require '../lib/Analog.php'; Analog::handler(Analog\Handler\Null::init()); Analog::log('Hellooooooo');
<?php require '../lib/Analog.php'; $log = ''; Analog::handler(Analog\Handler\LevelBuffer::init(Analog\Handler\Variable::init($log), Analog::CRITICAL)); // none of these will trigger sending the log Analog::log('Debugging...', Analog::DEBUG); Analog::log('Minor warning...', Analog::WARNING); Analog::log('An error...', Analog::ERROR); echo "Log is still empty:\n" . $log . "\n"; // but this will, and will include all the others in the log Analog::log('Oh noes!', Analog::URGENT); echo "Log now has everything:\n" . $log;
<?php // 1. Install the Amon PHP lib from http://amon.cx/guide/clients/php/ require 'amon.php'; require '../lib/Analog.php'; Analog::handler(Analog\Handler\Amon::init('http://127.0.0.1', 2464)); Analog::log('Error message'); Analog::log('Debug info', Analog::DEBUG);
<?php require '../lib/Analog.php'; $log_file = 'log.txt'; Analog::handler(Analog\Handler\File::init($log_file)); Analog::log('foo'); Analog::log('bar'); echo file_get_contents($log_file); unlink($log_file);
<?php require '../lib/Analog.php'; Analog::handler(Analog\Handler\FirePHP::init()); // debug-level message Analog::log(array('A debug message', __FILE__, __LINE__), Analog::DEBUG); // an info message Analog::log(array('An error message', __FILE__, __LINE__), Analog::INFO); // an error with no file/line #'s Analog::log('Another error message');
<?php require '../lib/Analog.php'; $log = ''; Analog::handler(Analog\Handler\Variable::init($log)); Analog::log('foo'); Analog::log('bar'); echo $log;
<?php require '../lib/Analog.php'; Analog::handler(Analog\Handler\Syslog::init('analog', 'user')); Analog::log('Error message', Analog::WARNING);