Navigation Menu

Skip to content

Commit

Permalink
Renamed param $type of LogInterface::write() to $level.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Dec 9, 2013
1 parent 3e544c2 commit cf6d65f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cake/Log/Engine/BaseLog.php
Expand Up @@ -65,7 +65,7 @@ public function config($config = null) {
}

/**
* Get the levls this logger is interested in.
* Get the levels this logger is interested in.
*
* @return array
*/
Expand Down
13 changes: 6 additions & 7 deletions Cake/Log/Engine/ConsoleLog.php
Expand Up @@ -22,7 +22,6 @@

/**
* Console logging. Writes logs to console output.
*
*/
class ConsoleLog extends BaseLog {

Expand All @@ -38,7 +37,7 @@ class ConsoleLog extends BaseLog {
*
* Config
*
* - `types` string or array, levels the engine is interested in
* - `levels` string or array, levels the engine is interested in
* - `scopes` string or array, scopes the engine is interested in
* - `stream` the path to save logs on.
* - `outputAs` integer or ConsoleOutput::[RAW|PLAIN|COLOR]
Expand All @@ -55,7 +54,7 @@ public function __construct($config = array()) {
}
$config = Hash::merge(array(
'stream' => 'php://stderr',
'types' => null,
'levels' => null,
'scopes' => array(),
'outputAs' => $outputAs,
), $this->_config);
Expand All @@ -73,15 +72,15 @@ public function __construct($config = array()) {
/**
* Implements writing to console.
*
* @param string $type The type of log you are making.
* @param string $level The severity level 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, $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);
public function write($level, $message, $scope = []) {
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message . "\n";
return $this->_output->write(sprintf('<%s>%s</%s>', $level, $output, $level), false);
}

}
19 changes: 10 additions & 9 deletions Cake/Log/Engine/FileLog.php
Expand Up @@ -118,15 +118,16 @@ public function config($config = array()) {
/**
* Implements writing to log files.
*
* @param string $type The type of log you are making.
* @param string $level The severity level of the message being written.
* See Cake\Log\Log::$_levels for list of possible levels.
* @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, $scope = []) {
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message . "\n";
$filename = $this->_getFilename($type);
public function write($level, $message, $scope = []) {
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message . "\n";
$filename = $this->_getFilename($level);
if (!empty($this->_size)) {
$this->_rotateFile($filename);
}
Expand All @@ -151,20 +152,20 @@ public function write($type, $message, $scope = []) {

/**
* Get filename
* @param string $type The type of log.
* @param string $level The level of log.
* @return string File name
*/
protected function _getFilename($type) {
protected function _getFilename($level) {
$debugTypes = array('notice', 'info', 'debug');

if (!empty($this->_file)) {
$filename = $this->_file;
} elseif ($type == 'error' || $type == 'warning') {
} elseif ($level == 'error' || $level == 'warning') {
$filename = 'error.log';
} elseif (in_array($type, $debugTypes)) {
} elseif (in_array($level, $debugTypes)) {
$filename = 'debug.log';
} else {
$filename = $type . '.log';
$filename = $level . '.log';
}

return $filename;
Expand Down
23 changes: 11 additions & 12 deletions Cake/Log/Engine/SyslogLog.php
Expand Up @@ -24,9 +24,8 @@
class SyslogLog extends BaseLog {

/**
*
* By default messages are formatted as:
* type: message
* level: message
*
* To override the log format (e.g. to add your own info) define the format key when configuring
* this logger
Expand All @@ -40,12 +39,12 @@ class SyslogLog extends BaseLog {
* ## Example:
*
* {{{
* CakeLog::config('error', array(
* Log::config('error', ]
* 'engine' => 'Syslog',
* 'types' => array('emergency', 'alert', 'critical', 'error'),
* 'levels' => ['emergency', 'alert', 'critical', 'error'],
* 'format' => "%s: My-App - %s",
* 'prefix' => 'Web Server 01'
* ));
* ]);
* }}}
*
* @var array
Expand All @@ -63,7 +62,7 @@ class SyslogLog extends BaseLog {
*
* @var array
*/
protected $_priorityMap = array(
protected $_levelMap = array(
'emergency' => LOG_EMERG,
'alert' => LOG_ALERT,
'critical' => LOG_CRIT,
Expand Down Expand Up @@ -95,30 +94,30 @@ public function __construct($config = array()) {
/**
* Writes a message to syslog
*
* Map the $type back to a LOG_ constant value, split multi-line messages into multiple
* Map the $level back to a LOG_ constant value, split multi-line messages into multiple
* log messages, pass all messages through the format defined in the configuration
*
* @param string $type The type of log you are making.
* @param string $level The severity level 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, $scope = []) {
public function write($level, $message, $scope = []) {
if (!$this->_open) {
$config = $this->_config;
$this->_open($config['prefix'], $config['flag'], $config['facility']);
$this->_open = true;
}

$priority = LOG_DEBUG;
if (isset($this->_priorityMap[$type])) {
$priority = $this->_priorityMap[$type];
if (isset($this->_levelMap[$level])) {
$priority = $this->_levelMap[$level];
}

$messages = explode("\n", $message);
foreach ($messages as $message) {
$message = sprintf($this->_config['format'], $type, $message);
$message = sprintf($this->_config['format'], $level, $message);
$this->_write($priority, $message);
}

Expand Down
4 changes: 2 additions & 2 deletions Cake/Log/Log.php
Expand Up @@ -319,8 +319,8 @@ public static function engine($name) {
* 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.
*
* @param integer|string $level The level of the message being written. The value must be
* an integer or string matching a known level.
* @param integer|string $level The severity level of the message being written.
* The value must be an integer or string matching a known level.
* @param string $message Message content 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.
Expand Down
11 changes: 6 additions & 5 deletions Cake/Log/LogInterface.php
Expand Up @@ -19,17 +19,18 @@
/**
* LogStreamInterface is the interface that should be implemented
* by all classes that are going to be used as Log streams.
*
*/
interface LogInterface {

/**
* Write method to handle writes being made to the Logger
*
* @param string $type
* @param string $message
* @param string|array $scope
* @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.
* See Cake\Log\Log::config() for more information on logging scopes.
* @return void
*/
public function write($type, $message, $scope = []);
public function write($level, $message, $scope = []);
}
2 changes: 1 addition & 1 deletion Cake/Test/TestApp/Log/Engine/TestAppLog.php
Expand Up @@ -26,7 +26,7 @@ class TestAppLog extends BaseLog {

public $passedScope = null;

public function write($type, $message, $scope = []) {
public function write($level, $message, $scope = []) {
$this->passedScope = $scope;
}

Expand Down
Expand Up @@ -22,7 +22,7 @@
*/
class TestPluginLog implements LogInterface {

public function write($type, $message, $scope = []) {
public function write($level, $message, $scope = []) {
}

}

0 comments on commit cf6d65f

Please sign in to comment.