From db68d401f67496ba5e495dd36adabe6d85187b44 Mon Sep 17 00:00:00 2001 From: Sai Phaninder Reddy Jonnala Date: Mon, 21 Dec 2015 11:33:57 -0500 Subject: Refactoring the `CI_Log` line formatting - Extracting the `CI_Log` line formatting into a protected function `_format_log_line()` so as to make it easy to change the log line format via extending the class and overriding the method. --- system/core/Log.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/system/core/Log.php b/system/core/Log.php index e8cb401f5..cf2793a56 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -204,7 +204,7 @@ class CI_Log { $date = date($this->_date_fmt); } - $message .= $level.' - '.$date.' --> '.$msg."\n"; + $message .= $this->_format_log_line($level, $date, $msg); flock($fp, LOCK_EX); @@ -227,4 +227,20 @@ class CI_Log { return is_int($result); } + /** + * Format the log line. + * + * This is for extensibility of log formatting. + * If you want to change the log format, + * extend the CI_Log class and override this method. + * + * @param $level + * @param $date + * @param $msg + * + * @return string formatted log line with a new line character '\n' at the end. + */ + protected function _format_log_line($level, $date, $msg){ + return $level.' - '.$date.' --> '.$msg."\n"; + } } -- cgit v1.2.3-24-g4f1b From 3ac1fd1af92a1d45f9624fff99f5e0692c59d7c6 Mon Sep 17 00:00:00 2001 From: Sai Phaninder Reddy Jonnala Date: Mon, 21 Dec 2015 12:27:40 -0500 Subject: fixing my blatant mistakes in styling the code --- system/core/Log.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system/core/Log.php b/system/core/Log.php index cf2793a56..0e1f7e2ac 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -234,13 +234,13 @@ class CI_Log { * If you want to change the log format, * extend the CI_Log class and override this method. * - * @param $level - * @param $date - * @param $msg - * - * @return string formatted log line with a new line character '\n' at the end. + * @param string the error level: 'error', 'debug' or 'info' + * @param string formatted date string + * @param string the log message + * @return string formatted log line with a new line character '\n' at the end. */ - protected function _format_log_line($level, $date, $msg){ + protected function _format_log_line($level, $date, $msg) + { return $level.' - '.$date.' --> '.$msg."\n"; } } -- cgit v1.2.3-24-g4f1b From 009ce6c4b68375f77bc8864528602824d6c603ba Mon Sep 17 00:00:00 2001 From: Sai Phaninder Reddy Jonnala Date: Fri, 15 Jan 2016 10:25:53 -0500 Subject: Code styling changes as suggested by narfbg --- system/core/Log.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/system/core/Log.php b/system/core/Log.php index 0e1f7e2ac..f338a36ec 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -154,8 +154,8 @@ class CI_Log { * * Generally this function will be called using the global log_message() function * - * @param string the error level: 'error', 'debug' or 'info' - * @param string the error message + * @param string $level The error level: 'error', 'debug' or 'info' + * @param string $msg The error message * @return bool */ public function write_log($level, $msg) @@ -204,7 +204,7 @@ class CI_Log { $date = date($this->_date_fmt); } - $message .= $this->_format_log_line($level, $date, $msg); + $message .= $this->_format_line($level, $date, $msg); flock($fp, LOCK_EX); @@ -227,6 +227,8 @@ class CI_Log { return is_int($result); } + // -------------------------------------------------------------------- + /** * Format the log line. * @@ -234,13 +236,13 @@ class CI_Log { * If you want to change the log format, * extend the CI_Log class and override this method. * - * @param string the error level: 'error', 'debug' or 'info' - * @param string formatted date string - * @param string the log message + * @param string $level The error level + * @param string $date Formatted date string + * @param string $msg The log message * @return string formatted log line with a new line character '\n' at the end. */ - protected function _format_log_line($level, $date, $msg) + protected function _format_line($level, $date, $message) { - return $level.' - '.$date.' --> '.$msg."\n"; + return $level.' - '.$date.' --> '.$message."\n"; } } -- cgit v1.2.3-24-g4f1b From e9aad049553f4f276093a1a212a2f03f20cb337d Mon Sep 17 00:00:00 2001 From: Sai Phaninder Reddy Jonnala Date: Mon, 8 Feb 2016 16:42:37 -0500 Subject: Doc block formatting change. --- system/core/Log.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/system/core/Log.php b/system/core/Log.php index f338a36ec..34ac64a27 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -232,14 +232,13 @@ class CI_Log { /** * Format the log line. * - * This is for extensibility of log formatting. - * If you want to change the log format, - * extend the CI_Log class and override this method. + * This is for extensibility of log formatting + * If you want to change the log format, extend the CI_Log class and override this method * * @param string $level The error level * @param string $date Formatted date string * @param string $msg The log message - * @return string formatted log line with a new line character '\n' at the end. + * @return string Formatted log line with a new line character '\n' at the end */ protected function _format_line($level, $date, $message) { -- cgit v1.2.3-24-g4f1b