Skip to content
This repository has been archived by the owner on Mar 2, 2019. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Hough committed Apr 29, 2014
2 parents dbdb5ed + 72e39fd commit a4f327d
Show file tree
Hide file tree
Showing 78 changed files with 2,584 additions and 283 deletions.
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
language: php

php:
- 5.2
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm

before_script:
- "mkdir -p ~/.composer"
- cp src/test/resources/travis-composer-config.json ~/.composer/config.json
- wget https://raw.github.com/ehough/throwback/develop/src/main/bash/travis-setup.sh
- if [ "`phpenv version-name`" != "hhvm" ]; then echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
- if [ "`phpenv version-name`" != "hhvm" ]; then echo "extension = amqp.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
- chmod a+x travis-setup.sh
- ./travis-setup.sh
script: "phpunit -c src/test/resources/phpunit.xml.dist"

script: "phpunit -c src/test/resources/phpunit.xml.dist --coverage-clover=coverage.clover"

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
2 changes: 1 addition & 1 deletion README.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Fork of [monolog](https://github.com/Seldaek/monolog) compatible with PHP 5.2+.

[monolog](https://github.com/Seldaek/monolog) is a fantastic logging library, but it's only compatible with PHP 5.3+. While 97% of PHP servers run PHP 5.2 or higher,
**32% of all servers are still running PHP 5.2 or lower** ([source](http://w3techs.com/technologies/details/pl-php/5/all)).
It would be a shame to exempt this library from nearly half of the world's servers just because of a few version incompatibilities.
It would be a shame to exempt this library from nearly a third of the world's servers just because of a few version incompatibilities.

Once PHP 5.3+ adoption levels near closer to 100%, this library will be retired.

Expand Down
34 changes: 27 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"name": "ehough/epilog",
"description": "Fork of seldaek/monolog compatible with PHP 5.2+.",
"description": "Fork of seldaek/monolog compatible with PHP 5.2+",
"homepage": "https://github.com/ehough/epilog",
"license": "MIT",
"authors": [
{
"name": "Jordi Boggiano",
"email": "[email protected]",
"homepage": "http://seld.be"
},
{
"name": "Eric Hough",
"email": "eric@ehough.com",
"email": "eric@tubepress.org",
"homepage": "http://ehough.com"
}
],
Expand All @@ -15,14 +20,29 @@
},
"require-dev": {
"phpunit/phpunit": "~3.7.0",
"mlehner/gelf-php": "1.0.*",
"raven/raven": "0.5.*",
"graylog2/gelf-php": "~1.0",
"raven/raven": "~0.5",
"ruflin/elastica": "0.90.*",
"doctrine/couchdb": "dev-master",
"aws/aws-sdk-php": "~2.4.8",
"doctrine/couchdb": "~1.0@dev",
"aws/aws-sdk-php": "~2.4, >2.4.8",
"ehough/pulsar": "~2.3"
},
"autoload": {
"psr-0": {"ehough_epilog": "src/main/php"}
},
"suggest": {
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
"raven/raven": "Allow sending log messages to a Sentry server",
"doctrine/couchdb": "Allow sending log messages to a CouchDB server",
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
"ext-mongo": "Allow sending log messages to a MongoDB server",
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
"rollbar/rollbar": "Allow sending log messages to Rollbar"
},
"extra": {
"branch-alias": {
"dev-master": "1.9.x-dev"
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/php/ehough/epilog/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function handleException(Exception $e)
{
$this->logger->log(
$this->uncaughtExceptionLevel === null ? ehough_epilog_psr_LogLevel::ERROR : $this->uncaughtExceptionLevel,
'Uncaught exception',
sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
array('exception' => $e)
);

Expand Down
17 changes: 10 additions & 7 deletions src/main/php/ehough/epilog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,19 @@ class ehough_epilog_Logger implements ehough_epilog_psr_LoggerInterface
);

/**
* @var DateTimeZone
* @var \DateTimeZone
*/
protected static $timezone;

/**
* @var string
*/
protected $name;

/**
* The handler stack
*
* @var array of ehough_epilog_handler_HandlerInterface
* @var ehough_epilog_handler_HandlerInterface[]
*/
protected $handlers;

Expand All @@ -114,14 +117,14 @@ class ehough_epilog_Logger implements ehough_epilog_psr_LoggerInterface
*
* To process records of a single handler instead, add the processor on that specific handler
*
* @var array of callables
* @var callable[]
*/
protected $processors;

/**
* @param string $name The logging channel
* @param array $handlers Optional stack of handlers, the first one in the array is called first, etc.
* @param array $processors Optional array of processors
* @param string $name The logging channel
* @param ehough_epilog_handler_HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc.
* @param callable[] $processors Optional array of processors
*/
public function __construct($name, array $handlers = array(), array $processors = array())
{
Expand Down Expand Up @@ -344,7 +347,7 @@ public function addAlert($message, array $context = array())
*/
public function addEmergency($message, array $context = array())
{
return $this->addRecord(self::EMERGENCY, $message, $context);
return $this->addRecord(self::EMERGENCY, $message, $context);
}

/**
Expand Down
114 changes: 114 additions & 0 deletions src/main/php/ehough/epilog/Registry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Monolog log registry
*
* Allows to get `Logger` instances in the global scope
* via static method calls on this class.
*
* <code>
* $application = new Monolog\Logger('application');
* $api = new Monolog\Logger('api');
*
* Monolog\Registry::addLogger($application);
* Monolog\Registry::addLogger($api);
*
* function testLogger()
* {
* Monolog\Registry::api()->addError('Sent to $api Logger instance');
* Monolog\Registry::application()->addError('Sent to $application Logger instance');
* }
* </code>
*
* @author Tomas Tatarko <[email protected]>
*/
class ehough_epilog_Registry
{
/**
* List of all loggers in the registry (ba named indexes)
*
* @var ehough_epilog_Logger[]
*/
private static $loggers = array();

/**
* Adds new logging channel to the registry
*
* @param ehough_epilog_Logger $logger Instance of the logging channel
* @param string|null $name Name of the logging channel ($logger->getName() by default)
* @param boolean $overwrite Overwrite instance in the registry if the given name already exists?
* @throws \InvalidArgumentException If $overwrite set to false and named Logger instance already exists
*/
public static function addLogger(ehough_epilog_Logger $logger, $name = null, $overwrite = false)
{
$name = $name ? $name : $logger->getName();

if (isset(self::$loggers[$name]) && !$overwrite) {
throw new InvalidArgumentException('Logger with the given name already exists');
}

self::$loggers[$name] = $logger;
}

/**
* Removes instance from registry by name or instance
*
* @param string|ehough_epilog_Logger $logger Name or logger instance
*/
public static function removeLogger($logger)
{
if ($logger instanceof ehough_epilog_Logger) {
if (false !== ($idx = array_search($logger, self::$loggers, true))) {
unset(self::$loggers[$idx]);
}
} else {
unset(self::$loggers[$logger]);
}
}

/**
* Clears the registry
*/
public static function clear()
{
self::$loggers = array();
}

/**
* Gets Logger instance from the registry
*
* @param string $name Name of the requested Logger instance
* @return ehough_epilog_Logger Requested instance of Logger
* @throws \InvalidArgumentException If named Logger instance is not in the registry
*/
public static function getInstance($name)
{
if (!isset(self::$loggers[$name])) {
throw new InvalidArgumentException(sprintf('Requested "%s" logger instance is not in the registry', $name));
}

return self::$loggers[$name];
}

/**
* Gets Logger instance from the registry via static method call
*
* @param string $name Name of the requested Logger instance
* @param array $arguments Arguments passed to static method call
* @return ehough_epilog_Logger Requested instance of Logger
* @throws \InvalidArgumentException If named Logger instance is not in the registry
*/
public static function __callStatic($name, $arguments)
{
return self::getInstance($name);
}
}
4 changes: 3 additions & 1 deletion src/main/php/ehough/epilog/formatter/ElasticaFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct($index, $type)
public function format(array $record)
{
$record = parent::format($record);

return $this->getDocument($record);
}

Expand All @@ -68,7 +69,7 @@ public function getType()
/**
* Convert a log message into an Elastica Document
*
* @param array $record Log message
* @param array $record Log message
* @return \Elastica\Document
*/
protected function getDocument($record)
Expand All @@ -77,6 +78,7 @@ protected function getDocument($record)
$document->setData($record);
$document->setType($this->type);
$document->setIndex($this->index);

return $document;
}
}
93 changes: 93 additions & 0 deletions src/main/php/ehough/epilog/formatter/FlowdockFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

/**
* formats the record to be used in the FlowdockHandler
*
* @author Dominik Liebler <[email protected]>
*/
class ehough_epilog_formatter_FlowdockFormatter implements ehough_epilog_formatter_FormatterInterface
{
/**
* @var string
*/
private $source;

/**
* @var string
*/
private $sourceEmail;

/**
* @param string $source
* @param string $sourceEmail
*/
public function __construct($source, $sourceEmail)
{
$this->source = $source;
$this->sourceEmail = $sourceEmail;
}

/**
* {@inheritdoc}
*/
public function format(array $record)
{
$tags = array(
'#logs',
'#' . strtolower($record['level_name']),
'#' . $record['channel'],
);

foreach ($record['extra'] as $value) {
$tags[] = '#' . $value;
}

$subject = sprintf(
'in %s: %s - %s',
$this->source,
$record['level_name'],
$this->getShortMessage($record['message'])
);

$record['flowdock'] = array(
'source' => $this->source,
'from_address' => $this->sourceEmail,
'subject' => $subject,
'content' => $record['message'],
'tags' => $tags,
'project' => $this->source,
);

return $record;
}

/**
* {@inheritdoc}
*/
public function formatBatch(array $records)
{
$formatted = array();

foreach ($records as $record) {
$formatted[] = $this->format($record);
}

return $formatted;
}

/**
* @param string $message
*
* @return string
*/
public function getShortMessage($message)
{
$maxLength = 45;

if (strlen($message) > $maxLength) {
$message = substr($message, 0, $maxLength - 4) . ' ...';
}

return $message;
}
}
Loading

0 comments on commit a4f327d

Please sign in to comment.