Browse Source

Remove use of LOGS constant for Log package.

ADmad 11 years ago
parent
commit
2c4474aa33

+ 5 - 2
src/Log/Engine/FileLog.php

@@ -44,7 +44,7 @@ class FileLog extends BaseLog {
  * @var array
  */
 	protected $_defaultConfig = [
-		'path' => LOGS,
+		'path' => null,
 		'file' => null,
 		'types' => null,
 		'levels' => [],
@@ -86,7 +86,10 @@ class FileLog extends BaseLog {
 		if (!empty($this->_config['path'])) {
 			$this->_path = $this->_config['path'];
 		}
-		if (Configure::read('debug') && !is_dir($this->_path)) {
+		if ($this->_path !== null &&
+			Configure::read('debug') &&
+			!is_dir($this->_path)
+		) {
 			mkdir($this->_path, 0775, true);
 		}
 

+ 1 - 1
tests/TestCase/Log/Engine/FileLogTest.php

@@ -68,7 +68,7 @@ class FileLogTest extends TestCase {
 	public function testLogFileWriting() {
 		$this->_deleteLogs(LOGS);
 
-		$log = new FileLog();
+		$log = new FileLog(['path' => LOGS]);
 		$log->log('warning', 'Test warning');
 		$this->assertTrue(file_exists(LOGS . 'error.log'));
 

+ 12 - 1
tests/TestCase/Log/LogTest.php

@@ -145,7 +145,7 @@ class LogTest extends TestCase {
 				'className' => 'File',
 				'path' => TMP . 'tests',
 			]],
-			'Direct instance' => [new FileLog()],
+			'Direct instance' => [new FileLog(['path' => LOGS])],
 		];
 	}
 
@@ -240,11 +240,13 @@ class LogTest extends TestCase {
 		}
 		Log::config('spam', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => 'debug',
 			'file' => 'spam',
 		));
 		Log::config('eggs', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => array('eggs', 'debug', 'error', 'warning'),
 			'file' => 'eggs',
 		));
@@ -274,11 +276,13 @@ class LogTest extends TestCase {
 	protected function _resetLogConfig() {
 		Log::config('debug', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => array('notice', 'info', 'debug'),
 			'file' => 'debug',
 		));
 		Log::config('error', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
 			'file' => 'error',
 		));
@@ -315,6 +319,7 @@ class LogTest extends TestCase {
 		$this->_resetLogConfig();
 		Log::config('shops', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => array('info', 'debug', 'warning'),
 			'scopes' => array('transactions', 'orders'),
 			'file' => 'shops',
@@ -361,6 +366,7 @@ class LogTest extends TestCase {
 		$this->_resetLogConfig();
 		Log::config('shops', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => array('info', 'debug', 'notice', 'warning'),
 			'scopes' => array('transactions', 'orders'),
 			'file' => 'shops',
@@ -400,12 +406,14 @@ class LogTest extends TestCase {
 
 		Log::config('shops', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => array('debug', 'notice', 'warning'),
 			'scopes' => array('transactions', 'orders'),
 			'file' => 'shops.log',
 		));
 		Log::config('eggs', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => array('debug', 'notice', 'warning'),
 			'scopes' => array('eggs'),
 			'file' => 'eggs.log',
@@ -432,6 +440,7 @@ class LogTest extends TestCase {
 
 		Log::config('scope_test', [
 			'engine' => 'TestApp',
+			'path' => LOGS,
 			'types' => array('notice', 'info', 'debug'),
 			'scopes' => array('foo', 'bar'),
 		]);
@@ -457,11 +466,13 @@ class LogTest extends TestCase {
 
 		Log::config('debug', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => array('notice', 'info', 'debug'),
 			'file' => 'debug',
 		));
 		Log::config('error', array(
 			'engine' => 'File',
+			'path' => LOGS,
 			'types' => array('emergency', 'alert', 'critical', 'error', 'warning'),
 			'file' => 'error',
 		));