Skip to content
Permalink
Browse files

Pass scope to log engines.

  • Loading branch information...
ADmad committed Dec 7, 2013
1 parent 1b6f948 commit d819fa48c1782d49506438806182f83d94e70ddf
@@ -75,9 +75,11 @@ public function __construct($config = array()) {
*
* @param string $type The type of log you are making.
* @param string $message The message you want to log.
* @param string|array $scope The scope(s) a log message is being created in.
* See Cake\Log\Log::config() for more information on logging scopes.
* @return boolean success of write.
*/
public function write($type, $message) {
public function write($type, $message, $scope = []) {
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message . "\n";
return $this->_output->write(sprintf('<%s>%s</%s>', $type, $output, $type), false);
}
@@ -120,9 +120,11 @@ public function config($config = array()) {
*
* @param string $type The type of log you are making.
* @param string $message The message you want to log.
* @param string|array $scope The scope(s) a log message is being created in.
* See Cake\Log\Log::config() for more information on logging scopes.
* @return boolean success of write.
*/
public function write($type, $message) {
public function write($type, $message, $scope = []) {
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message . "\n";
$filename = $this->_getFilename($type);
if (!empty($this->_size)) {
@@ -100,9 +100,11 @@ public function __construct($config = array()) {
*
* @param string $type The type of log you are making.
* @param string $message The message you want to log.
* @param string|array $scope The scope(s) a log message is being created in.
* See Cake\Log\Log::config() for more information on logging scopes.
* @return boolean success of write.
*/
public function write($type, $message) {
public function write($type, $message, $scope = []) {
if (!$this->_open) {
$config = $this->_config;
$this->_open($config['prefix'], $config['flag'], $config['facility']);
@@ -348,7 +348,7 @@ public static function write($level, $message, $scope = array()) {
count(array_intersect((array)$scope, $scopes)) > 0
);
if ($correctLevel && $inScope) {
$logger->write($level, $message);
$logger->write($level, $message, $scope);
$logged = true;
}
}
@@ -28,7 +28,8 @@ interface LogInterface {
*
* @param string $type
* @param string $message
* @param string|array $scope
* @return void
*/
public function write($type, $message);
public function write($type, $message, $scope = []);
}
@@ -24,7 +24,10 @@
*/
class TestAppLog extends BaseLog {
public function write($type, $message) {
public $passedScope = null;
public function write($type, $message, $scope = []) {
$this->passedScope = $scope;
}
}
@@ -22,7 +22,7 @@
*/
class TestPluginLog implements LogInterface {
public function write($type, $message) {
public function write($type, $message, $scope = []) {
}
}
@@ -406,6 +406,33 @@ public function testScopedLoggingExclusive() {
$this->assertFalse(file_exists(LOGS . 'shops.log'));
}
/**
* testPassingScopeToEngine method
*/
public function testPassingScopeToEngine() {
Configure::write('App.namespace', 'TestApp');
Log::reset();
Log::config('scope_test', [
'engine' => 'TestApp',
'types' => array('notice', 'info', 'debug'),
'scopes' => array('foo', 'bar'),
]);
$engine = Log::engine('scope_test');
$this->assertNull($engine->passedScope);
Log::write('debug', 'test message', 'foo');
$this->assertEquals('foo', $engine->passedScope);
Log::write('debug', 'test message', ['foo', 'bar']);
$this->assertEquals(['foo', 'bar'], $engine->passedScope);
$result = Log::write('debug', 'test message');
$this->assertFalse($result);
}
/**
* test convenience methods
*/

0 comments on commit d819fa4

Please sign in to comment.
You can’t perform that action at this time.