Skip to content
Permalink
Browse files

Starting work to make Cake PSR-3 compliant and accept monolog as an

alternate logger without much pain
  • Loading branch information...
lorenzo committed Sep 19, 2014
1 parent a183391 commit ff1161d8c87354082d62677b6dd09251b7f560f2
Showing with 24 additions and 21 deletions.
  1. +2 −1 composer.json
  2. +2 −2 src/Log/Engine/BaseLog.php
  3. +11 −11 src/Log/Log.php
  4. +4 −4 src/Log/LogEngineRegistry.php
  5. +5 −3 src/Log/LogInterface.php
@@ -24,7 +24,8 @@
"ext-mbstring": "*",
"nesbot/Carbon": "1.8.*",
"ircmaxell/password-compat": "1.0.*",
"aura/intl": "1.1.*"
"aura/intl": "1.1.*",
"psr/log": "1.0"
},
"require-dev": {
"phpunit/phpunit": "*"
@@ -15,13 +15,13 @@
namespace Cake\Log\Engine;
use Cake\Core\InstanceConfigTrait;
use Cake\Log\LogInterface;
use Psr\Log\AbstractLogger;
/**
* Base log engine class.
*
*/
abstract class BaseLog implements LogInterface {
abstract class BaseLog extends AbstractLogger {
use InstanceConfigTrait;
@@ -36,7 +36,7 @@
* classname to use loggers in the `App\Log\Engine` & `Cake\Log\Engine` namespaces.
* You can also use plugin short hand to use logging classes provided by plugins.
*
* Log adapters are required to implement `Cake\Log\LogInterface`, and there is a
* Log adapters are required to implement `Psr\Log\LoggerInterface`, and there is a
* built-in base class (`Cake\Log\Engine\BaseLog`) that can be used for custom loggers.
*
* Outside of the `className` key, all other configuration values will be passed to the
@@ -308,7 +308,7 @@ public static function engine($name) {
*
* If no configured logger can handle a log message (because of level or scope restrictions)
* then the logged message will be ignored and silently dropped. You can check if this has happened
* by inspecting the return of write(). If false the message was not handled.
* by inspecting the return of write(). If false the message was not handled.
*
* @param int|string $level The severity level of the message being written.
* The value must be an integer or string matching a known level.
@@ -329,26 +329,26 @@ public static function write($level, $message, $scope = array()) {
}
$logged = false;
$scope = (array)$scope;
foreach (static::$_registry->loaded() as $streamName) {
$logger = static::$_registry->{$streamName};
$levels = $scopes = null;
if ($logger instanceof BaseLog) {
$levels = $logger->levels();
$scopes = $logger->scopes();
}
$correctLevel = (
empty($levels) ||
in_array($level, $levels)
);
$inScope = (
empty($scopes) ||
count(array_intersect((array)$scope, $scopes)) > 0
);
$correctLevel = empty($levels) || in_array($level, $levels);
$inScope = empty($scopes) || array_intersect($scope, $scopes);
if ($correctLevel && $inScope) {
$logger->write($level, $message, $scope);
$logger->log($level, $message, $scope);
$logged = true;
}
}
return $logged;
}
@@ -16,8 +16,8 @@
use Cake\Core\App;
use Cake\Core\ObjectRegistry;
use Cake\Log\LogInterface;
use \RuntimeException;
use Psr\Log\LoggerInterface;
use RuntimeException;
/**
* Registry of loaded log engines
@@ -74,12 +74,12 @@ protected function _create($class, $alias, $settings) {
$instance = new $class($settings);
}
if ($instance instanceof LogInterface) {
if ($instance instanceof LoggerInterface) {
return $instance;
}
throw new RuntimeException(
'Loggers must implement Cake\Log\LogInterface.'
'Loggers must implement Psr\Log\LoggerInterface.'
);
}
@@ -16,19 +16,21 @@
*/
namespace Cake\Log;
use Psr\Log\LoggerInterface;
/**
* LogStreamInterface is the interface that should be implemented
* LogInterface is the interface that should be implemented
* by all classes that are going to be used as Log streams.
*/
interface LogInterface {
interface LogInterface extends LoggerInterface {
/**
* Write method to handle writes being made to the Logger
*
* @param string $level The severity level of the message being written.
* See Cake\Log\Log::$_levels for list of possible levels.
* @param string $message Message content to log
* @param string|array $scope The scope(s) a log message is being created in.
* @param array $scope The scope(s) a log message is being created in.
* See Cake\Log\Log::config() for more information on logging scopes.
* @return void
*/

0 comments on commit ff1161d

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