Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Nov 18, 2014
2 parents 248d5b7 + 4a95165 commit 94c4d72
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 28 deletions.
15 changes: 15 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__);

return Symfony\CS\Config\Config::create()
->fixers(array(
'-concat_without_spaces',
'-new_with_braces',
'align_double_arrow',
'align_equals',
'ordered_use',
'short_array_syntax',
))
->finder($finder);
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Stump Changelog

### 0.3.0 (2014-11-19)

* **[IMPROVED]** Improved readability of log output by moving the date to the start of the line and using a fixed-width log level string
* **[BC, FIXED]** `Logger::substitutePlaceholders()` is now (correctly) marked as `private`

### 0.2.0 (2014-10-25)

* **[BC]** Replaced `PrefixableLoggerInterface` with `ParentLoggerInterface` which allows for chaning of "sub-loggers"
* **[BC]** Replaced `PrefixableLoggerInterface` with `ParentLoggerInterface` which allows for chaining of "sub-loggers"

### 0.1.1 (2014-10-24)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ INFO 2014-10-24 16:26:13: It's better than bad... it's good!
<!-- references -->
[Build Status]: http://img.shields.io/travis/IcecaveStudios/stump/develop.svg?style=flat-square
[Test Coverage]: http://img.shields.io/coveralls/IcecaveStudios/stump/develop.svg?style=flat-square
[SemVer]: http://img.shields.io/:semver-0.2.0-yellow.svg?style=flat-square
[SemVer]: http://img.shields.io/:semver-0.3.0-yellow.svg?style=flat-square
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"extra": {
"branch-alias": {
"dev-develop": "0.2.x-dev"
"dev-develop": "0.3.x-dev"
}
}
}
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
namespace Icecave\Stump;

use Icecave\Isolator\IsolatorTrait;
use Psr\Log\LogLevel;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
use Psr\Log\LogLevel;

/**
* A very simple PSR-3 logger implementation that writes to STDOUT.
Expand All @@ -28,8 +28,8 @@ public function __construct(
$dateFormat = 'Y-m-d H:i:s'
) {
$this->minimumLogLevel = self::$levels[$minimumLogLevel];
$this->dateFormat = $dateFormat;
$this->fileName = $fileName;
$this->dateFormat = $dateFormat;
$this->fileName = $fileName;
}

/**
Expand Down Expand Up @@ -60,9 +60,9 @@ public function log($level, $message, array $context = [])
->fwrite(
$this->stream,
sprintf(
'%s %s: %s' . PHP_EOL,
strtoupper($level),
'%s %s %s' . PHP_EOL,
$dateTime,
self::$levelText[$level],
$this->substitutePlaceholders(
$message,
$context
Expand All @@ -79,7 +79,7 @@ public function log($level, $message, array $context = [])
*
* @return string The message template with placeholder values substituted.
*/
public function substitutePlaceholders($message, array $context)
private function substitutePlaceholders($message, array $context)
{
if (false === strpos($message, '{')) {
return $message;
Expand All @@ -104,6 +104,17 @@ public function substitutePlaceholders($message, array $context)
LogLevel::DEBUG => 0,
];

private static $levelText = [
LogLevel::EMERGENCY => 'EMER',
LogLevel::ALERT => 'ALRT',
LogLevel::CRITICAL => 'CRIT',
LogLevel::ERROR => 'ERRO',
LogLevel::WARNING => 'WARN',
LogLevel::NOTICE => 'NOTC',
LogLevel::INFO => 'INFO',
LogLevel::DEBUG => 'DEBG',
];

private $minimumLogLevel;
private $dateFormat;
private $fileName;
Expand Down
4 changes: 2 additions & 2 deletions src/PackageInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

class PackageInfo
{
const NAME = 'Stump';
const VERSION = '0.2.0';
const NAME = 'Stump';
const VERSION = '0.3.0';
}
34 changes: 26 additions & 8 deletions test/suite/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
namespace Icecave\Stump;

use Icecave\Isolator\Isolator;
use Phake;
use PHPUnit_Framework_TestCase;
use Phake;
use Psr\Log\LogLevel;

class LoggerTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->isolator = Phake::mock('Icecave\Isolator\Isolator');
$this->minimumLogLevel = LogLevel::INFO;

Phake::when($this->isolator)
->fopen(Phake::anyParameters())
Expand All @@ -21,16 +20,19 @@ public function setUp()
->date(Phake::anyParameters())
->thenReturn('<date>');

$this->logger = new Logger($this->minimumLogLevel);
$this->logger = new Logger;

$this->logger->setIsolator($this->isolator);
}

public function testLog()
/**
* @dataProvider logTestVectors
*/
public function testLog($logLevel, $logLevelText)
{
$this->logger->log(
LogLevel::WARNING,
'Warning message.'
$logLevel,
'Test message.'
);

Phake::verify($this->isolator)->fopen(
Expand All @@ -40,10 +42,24 @@ public function testLog()

Phake::verify($this->isolator)->fwrite(
'<resource>',
'WARNING <date>: Warning message.' . PHP_EOL
'<date> ' . $logLevelText . ' Test message.' . PHP_EOL
);
}

public function logTestVectors()
{
return [
[LogLevel::EMERGENCY, 'EMER'],
[LogLevel::ALERT, 'ALRT'],
[LogLevel::CRITICAL, 'CRIT'],
[LogLevel::ERROR, 'ERRO'],
[LogLevel::WARNING, 'WARN'],
[LogLevel::NOTICE, 'NOTC'],
[LogLevel::INFO, 'INFO'],
[LogLevel::DEBUG, 'DEBG'],
];
}

public function testLogWithPlaceholderValues()
{
$this->logger->log(
Expand All @@ -57,12 +73,14 @@ public function testLogWithPlaceholderValues()

Phake::verify($this->isolator)->fwrite(
'<resource>',
'INFO <date>: Foo: FOO, F: F, Missing: {missing}' . PHP_EOL
'<date> INFO Foo: FOO, F: F, Missing: {missing}' . PHP_EOL
);
}

public function testLogIgnoresLowLogLevel()
{
$this->logger = new Logger(LogLevel::INFO);

$this->logger->debug('This should not be logged.');

Phake::verifyNoInteraction($this->isolator);
Expand Down
2 changes: 1 addition & 1 deletion test/suite/ParentLoggerTraitTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace Icecave\Stump;

use Phake;
use PHPUnit_Framework_TestCase;
use Phake;

class ParentLoggerTraitTest extends PHPUnit_Framework_TestCase
{
Expand Down
4 changes: 2 additions & 2 deletions test/suite/SubLoggerTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace Icecave\Stump;

use Phake;
use PHPUnit_Framework_TestCase;
use Psr\Log\LoggerInterface;
use Phake;
use Psr\Log\LogLevel;
use Psr\Log\LoggerInterface;

class SubLoggerTest extends PHPUnit_Framework_TestCase
{
Expand Down

0 comments on commit 94c4d72

Please sign in to comment.