Skip to content

Commit

Permalink
unify engine to not require the suffix (as Cache and other places do).
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Jun 21, 2013
1 parent 0d486bd commit cb24dbb
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 25 deletions.
6 changes: 3 additions & 3 deletions lib/Cake/Log/CakeLog.php
Expand Up @@ -34,7 +34,7 @@
* A sample configuration would look like:
*
* {{{
* CakeLog::config('my_log', array('engine' => 'FileLog'));
* CakeLog::config('my_log', array('engine' => 'File'));
* }}}
*
* See the documentation on CakeLog::config() for more detail.
Expand Down Expand Up @@ -133,7 +133,7 @@ protected static function _init() {
*
* {{{
* CakeLog::config('second_file', array(
* 'engine' => 'FileLog',
* 'engine' => 'File',
* 'path' => '/var/logs/my_app/'
* ));
* }}}
Expand Down Expand Up @@ -378,7 +378,7 @@ public static function stream($streamName) {
*/
protected static function _autoConfig() {
self::$_Collection->load('default', array(
'engine' => 'FileLog',
'engine' => 'File',
'path' => LOGS,
));
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Cake/Log/LogEngineCollection.php
Expand Up @@ -63,7 +63,9 @@ public function load($name, $options = array()) {
*/
protected static function _getLogger($loggerName) {
list($plugin, $loggerName) = pluginSplit($loggerName, true);

if (substr($loggerName, -3) !== 'Log') {
$loggerName .= 'Log';
}
App::uses($loggerName, $plugin . 'Log/Engine');
if (!class_exists($loggerName)) {
throw new CakeLogException(__d('cake_dev', 'Could not load class %s', $loggerName));
Expand Down
50 changes: 31 additions & 19 deletions lib/Cake/Test/Case/Log/CakeLogTest.php
Expand Up @@ -87,6 +87,18 @@ public function testImportingLoggerFailure() {
* @return void
*/
public function testValidKeyName() {
CakeLog::config('valid', array('engine' => 'File'));
$stream = CakeLog::stream('valid');
$this->assertInstanceOf('FileLog', $stream);
CakeLog::drop('valid');
}

/**
* test config() with valid key name including the deprecated Log suffix
*
* @return void
*/
public function testValidKeyNameLogSuffix() {
CakeLog::config('valid', array('engine' => 'FileLog'));
$stream = CakeLog::stream('valid');
$this->assertInstanceOf('FileLog', $stream);
Expand All @@ -100,7 +112,7 @@ public function testValidKeyName() {
* @return void
*/
public function testInvalidKeyName() {
CakeLog::config('1nv', array('engine' => 'FileLog'));
CakeLog::config('1nv', array('engine' => 'File'));
}

/**
Expand Down Expand Up @@ -144,7 +156,7 @@ public function testAutoConfig() {
*/
public function testConfig() {
CakeLog::config('file', array(
'engine' => 'FileLog',
'engine' => 'File',
'path' => LOGS
));
$result = CakeLog::configured();
Expand All @@ -168,7 +180,7 @@ public function testConfig() {
*/
public function testDrop() {
CakeLog::config('file', array(
'engine' => 'FileLog',
'engine' => 'File',
'path' => LOGS
));
$result = CakeLog::configured();
Expand Down Expand Up @@ -214,12 +226,12 @@ public function testSelectiveLoggingByLevel() {
unlink(LOGS . 'eggs.log');
}
CakeLog::config('spam', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => 'debug',
'file' => 'spam',
));
CakeLog::config('eggs', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('eggs', 'debug', 'error', 'warning'),
'file' => 'eggs',
));
Expand Down Expand Up @@ -253,7 +265,7 @@ public function testSelectiveLoggingByLevel() {
*/
public function testStreamEnable() {
CakeLog::config('spam', array(
'engine' => 'FileLog',
'engine' => 'File',
'file' => 'spam',
));
$this->assertTrue(CakeLog::enabled('spam'));
Expand All @@ -268,7 +280,7 @@ public function testStreamEnable() {
*/
public function testStreamDisable() {
CakeLog::config('spam', array(
'engine' => 'FileLog',
'engine' => 'File',
'file' => 'spam',
));
$this->assertTrue(CakeLog::enabled('spam'));
Expand Down Expand Up @@ -298,12 +310,12 @@ public function testStreamDisableInvalid() {

protected function _resetLogConfig() {
CakeLog::config('debug', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));
Expand Down Expand Up @@ -339,7 +351,7 @@ public function testScopedLoggingBC() {
$this->_resetLogConfig();

CakeLog::config('shops', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('info', 'notice', 'warning'),
'scopes' => array('transactions', 'orders'),
'file' => 'shops',
Expand Down Expand Up @@ -393,13 +405,13 @@ public function testScopedLoggingExclusive() {
$this->_deleteLogs();

CakeLog::config('shops', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('info', 'notice', 'warning'),
'scopes' => array('transactions', 'orders'),
'file' => 'shops.log',
));
CakeLog::config('eggs', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('info', 'notice', 'warning'),
'scopes' => array('eggs'),
'file' => 'eggs.log',
Expand All @@ -426,7 +438,7 @@ public function testScopedLogging() {
$this->_deleteLogs();

CakeLog::config('string-scope', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('info', 'notice', 'warning'),
'scopes' => 'string-scope',
'file' => 'string-scope.log'
Expand All @@ -437,7 +449,7 @@ public function testScopedLogging() {
CakeLog::drop('string-scope');

CakeLog::config('shops', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('info', 'notice', 'warning'),
'scopes' => array('transactions', 'orders'),
'file' => 'shops.log',
Expand Down Expand Up @@ -526,7 +538,7 @@ public function testConvenienceScopedLogging() {

$this->_resetLogConfig();
CakeLog::config('shops', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('info', 'debug', 'notice', 'warning'),
'scopes' => array('transactions', 'orders'),
'file' => 'shops',
Expand Down Expand Up @@ -563,12 +575,12 @@ public function testConvenienceMethods() {
$this->_deleteLogs();

CakeLog::config('debug', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('emergency', 'alert', 'critical', 'error', 'warning'),
'file' => 'error',
));
Expand Down Expand Up @@ -677,12 +689,12 @@ public function testCustomLevelWrites() {
$this->assertContains('Error: ' . $testMessage, $contents);

CakeLog::config('spam', array(
'engine' => 'FileLog',
'engine' => 'File',
'file' => 'spam.log',
'types' => 'spam',
));
CakeLog::config('eggs', array(
'engine' => 'FileLog',
'engine' => 'File',
'file' => 'eggs.log',
'types' => array('spam', 'eggs'),
));
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Log/Engine/ConsoleLogTest.php
Expand Up @@ -52,12 +52,12 @@ class ConsoleLogTest extends CakeTestCase {
public function setUp() {
parent::setUp();
CakeLog::config('debug', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'engine' => 'File',
'types' => array('error', 'warning'),
'file' => 'error',
));
Expand Down
90 changes: 90 additions & 0 deletions lib/Cake/Test/Case/Log/LogEngineCollectionTest.php
@@ -0,0 +1,90 @@
<?php
/**
* LogEngineCollectionTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Log
* @since CakePHP(tm) v 2.4
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('LogEngineCollection', 'Log');
App::uses('FileLog', 'Log/Engine');

/**
* LoggerEngineLog class
*/
class LoggerEngineLog extends FileLog {
}

/**
* LogEngineCollectionTest class
*
* @package Cake.Test.Case.Log
*/
class LogEngineCollectionTest extends CakeTestCase {

public $Collection;

/**
* Start test callback
*
* @return void
*/
public function setUp() {
parent::setUp();

$this->Collection = new LogEngineCollection();
}

/**
* test load
*
* @return void
*/
public function testLoad() {
$result = $this->Collection->load('key', array('engine' => 'File'));
$this->assertInstanceOf('CakeLogInterface', $result);
}

/**
* test load with deprecated Log suffix
*
* @return void
*/
public function testLoadWithSuffix() {
$result = $this->Collection->load('key', array('engine' => 'FileLog'));
$this->assertInstanceOf('CakeLogInterface', $result);
}

/**
* test that engines starting with Log also work properly
*
* @return void
*/
public function testLoadWithSuffixAtBeginning() {
$result = $this->Collection->load('key', array('engine' => 'LoggerEngine'));
$this->assertInstanceOf('CakeLogInterface', $result);
}

/**
* test load with invalid Log
*
* @return void
* @expectedException CakeLogException
*/
public function testLoadInvalid() {
$result = $this->Collection->load('key', array('engine' => 'ImaginaryFile'));
$this->assertInstanceOf('CakeLogInterface', $result);
}

}

0 comments on commit cb24dbb

Please sign in to comment.