From 333f9f98edeb11915c168ea4a05b9b76d64d9576 Mon Sep 17 00:00:00 2001 From: Nithin Date: Sun, 21 Aug 2011 16:52:06 -0400 Subject: added ability to log certain error types, not all under a threshold --- system/libraries/Log.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 9f1db76ba..bf10d4727 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -27,10 +27,12 @@ class CI_Log { protected $_log_path; - protected $_threshold = 1; - protected $_date_fmt = 'Y-m-d H:i:s'; - protected $_enabled = TRUE; - protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + protected $_threshold = 1; + protected $_threshold_max = 0; + protected $_threshold_array = array(); + protected $_date_fmt = 'Y-m-d H:i:s'; + protected $_enabled = TRUE; + protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); /** * Constructor @@ -50,6 +52,11 @@ class CI_Log { { $this->_threshold = $config['log_threshold']; } + elseif (is_array($config['log_threshold'])) + { + $this->_threshold = $this->_threshold_max; + $this->_threshold_array = array_flip($config['log_threshold']); + } if ($config['log_date_format'] != '') { @@ -80,9 +87,13 @@ class CI_Log { if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) { - return FALSE; + if (empty($this->_threshold_array) OR ! isset($this->_threshold_array[$this->_levels[$level]])) + { + return FALSE; + } } + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; $message = ''; -- cgit v1.2.3-24-g4f1b From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Log.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index bf10d4727..6ea905f73 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource @@ -21,7 +33,7 @@ * @package CodeIgniter * @subpackage Libraries * @category Logging - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/general/errors.html */ class CI_Log { -- cgit v1.2.3-24-g4f1b From 2835e08ac46ab5c260978a2013ba8837222318c5 Mon Sep 17 00:00:00 2001 From: Jeroen van der Gulik Date: Sun, 4 Dec 2011 14:19:38 +0100 Subject: - Stop logger from trying to chmod on each event to safe i/o and prevent error messages popping up when the user is different then the webserver --- system/libraries/Log.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 6ea905f73..46c5b6ed2 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -111,6 +111,7 @@ class CI_Log { if ( ! file_exists($filepath)) { + $newfile = TRUE; $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } @@ -126,7 +127,10 @@ class CI_Log { flock($fp, LOCK_UN); fclose($fp); - @chmod($filepath, FILE_WRITE_MODE); + if (isset($newfile) AND $newfile === TRUE) + { + @chmod($filepath, FILE_WRITE_MODE); + } return TRUE; } @@ -134,4 +138,4 @@ class CI_Log { // END Log Class /* End of file Log.php */ -/* Location: ./system/libraries/Log.php */ \ No newline at end of file +/* Location: ./system/libraries/Log.php */ -- cgit v1.2.3-24-g4f1b From 76cc9200696b881a3318efd982dbded5f4f2851e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Dec 2011 20:02:04 +0200 Subject: Clean up the Log library --- system/libraries/Log.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 46c5b6ed2..7f3a307f3 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -1,13 +1,13 @@ - '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); /** * Constructor @@ -62,7 +62,7 @@ class CI_Log { if (is_numeric($config['log_threshold'])) { - $this->_threshold = $config['log_threshold']; + $this->_threshold = (int) $config['log_threshold']; } elseif (is_array($config['log_threshold'])) { @@ -97,12 +97,10 @@ class CI_Log { $level = strtoupper($level); - if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + AND ! isset($this->_threshold_array[$this->_levels[$level]])) { - if (empty($this->_threshold_array) OR ! isset($this->_threshold_array[$this->_levels[$level]])) - { - return FALSE; - } + return FALSE; } @@ -112,7 +110,7 @@ class CI_Log { if ( ! file_exists($filepath)) { $newfile = TRUE; - $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/libraries/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 7f3a307f3..944173fdd 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/libraries/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 944173fdd..955277acc 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 443bbd96382552e8a7aea0f9dc7f1c90efc9b4e8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Apr 2012 15:49:11 +0300 Subject: Minor cleanup and style fixes in the Log and Javascript libraries --- system/libraries/Log.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 955277acc..66f9ebff9 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Logging Class * @@ -43,12 +41,9 @@ class CI_Log { protected $_threshold_max = 0; protected $_threshold_array = array(); protected $_date_fmt = 'Y-m-d H:i:s'; - protected $_enabled = TRUE; - protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); + protected $_enabled = TRUE; + protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); - /** - * Constructor - */ public function __construct() { $config =& get_config(); @@ -98,7 +93,7 @@ class CI_Log { $level = strtoupper($level); if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) - AND ! isset($this->_threshold_array[$this->_levels[$level]])) + && ! isset($this->_threshold_array[$this->_levels[$level]])) { return FALSE; } @@ -125,15 +120,15 @@ class CI_Log { flock($fp, LOCK_UN); fclose($fp); - if (isset($newfile) AND $newfile === TRUE) + if (isset($newfile) && $newfile === TRUE) { @chmod($filepath, FILE_WRITE_MODE); } + return TRUE; } } -// END Log Class /* End of file Log.php */ -/* Location: ./system/libraries/Log.php */ +/* Location: ./system/libraries/Log.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b82bc3a016ce01dfeb993da5918853625a40af86 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 27 Apr 2012 09:12:58 -0400 Subject: Fix Cache, Image_lib and Log libraries --- system/libraries/Log.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 66f9ebff9..c10363a2e 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -36,14 +36,60 @@ */ class CI_Log { + /** + * Path to save log files + * + * @var string + */ protected $_log_path; + + /** + * Level of logging + * + * @var int + */ protected $_threshold = 1; + + /** + * Highest level of logging + * + * @var int + */ protected $_threshold_max = 0; + + /** + * Array of threshold levels to log + * + * @var array + */ protected $_threshold_array = array(); + + /** + * Format of timestamp for log files + * + * @var string + */ protected $_date_fmt = 'Y-m-d H:i:s'; + + /** + * Whether or not the logger can write to the log files + * + * @var bool + */ protected $_enabled = TRUE; + + /** + * Predefined logging levels + * + * @var array + */ protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); + /** + * Initialize Logging class + * + * @return void + */ public function __construct() { $config =& get_config(); -- cgit v1.2.3-24-g4f1b From 5645479c622eb36cf9869797896dc0921568c4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:32:19 +0300 Subject: Clean up the libraries --- system/libraries/Log.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index c10363a2e..51ce43dc7 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -42,42 +42,42 @@ class CI_Log { * @var string */ protected $_log_path; - + /** * Level of logging * * @var int */ protected $_threshold = 1; - + /** * Highest level of logging * * @var int */ protected $_threshold_max = 0; - + /** * Array of threshold levels to log * * @var array */ protected $_threshold_array = array(); - + /** * Format of timestamp for log files * * @var string */ protected $_date_fmt = 'Y-m-d H:i:s'; - + /** * Whether or not the logger can write to the log files * * @var bool */ protected $_enabled = TRUE; - + /** * Predefined logging levels * @@ -88,7 +88,7 @@ class CI_Log { /** * Initialize Logging class * - * @return void + * @return void */ public function __construct() { @@ -151,7 +151,7 @@ class CI_Log { if ( ! file_exists($filepath)) { $newfile = TRUE; - $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + $message .= '<'."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) @@ -159,7 +159,7 @@ class CI_Log { return FALSE; } - $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n"; + $message .= $level.' '.($level === 'INFO' ? ' -' : '-').' '.date($this->_date_fmt).' --> '.$msg."\n"; flock($fp, LOCK_EX); fwrite($fp, $message); -- cgit v1.2.3-24-g4f1b From d261b1e89c3d4d5191036d5a5660ef6764e593a0 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:16 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/libraries --- system/libraries/Log.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 51ce43dc7..baac80121 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -94,7 +94,7 @@ class CI_Log { { $config =& get_config(); - $this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : APPPATH.'logs/'; + $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path)) { @@ -111,7 +111,7 @@ class CI_Log { $this->_threshold_array = array_flip($config['log_threshold']); } - if ($config['log_date_format'] != '') + if ($config['log_date_format'] !== '') { $this->_date_fmt = $config['log_date_format']; } -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/libraries/Log.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index baac80121..a4dd47f86 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -1,4 +1,4 @@ -\n\n"; + $message .= '<'."?php if defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n"; } if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) -- cgit v1.2.3-24-g4f1b From fc2fbc55fbb234b842d9e9462e766211588d4880 Mon Sep 17 00:00:00 2001 From: Razican Date: Sat, 3 Nov 2012 13:52:34 +0100 Subject: Fixed typo in logs. --- system/libraries/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index a4dd47f86..e66270840 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -152,7 +152,7 @@ class CI_Log { if ( ! file_exists($filepath)) { $newfile = TRUE; - $message .= '<'."?php if defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n"; + $message .= '<'."?php defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n"; } if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) -- cgit v1.2.3-24-g4f1b From 0aeee85b5164e31e2a76c05caa97bd898c1a776d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Nov 2012 17:43:11 +0200 Subject: Move the Log class to system/core/ It is a core class after all, I guess somebody forgot it when the rest of them were moved. --- system/libraries/Log.php | 181 ----------------------------------------------- 1 file changed, 181 deletions(-) delete mode 100644 system/libraries/Log.php (limited to 'system/libraries/Log.php') diff --git a/system/libraries/Log.php b/system/libraries/Log.php deleted file mode 100644 index e66270840..000000000 --- a/system/libraries/Log.php +++ /dev/null @@ -1,181 +0,0 @@ - 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); - - /** - * Initialize Logging class - * - * @return void - */ - public function __construct() - { - $config =& get_config(); - - $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; - - if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path)) - { - $this->_enabled = FALSE; - } - - if (is_numeric($config['log_threshold'])) - { - $this->_threshold = (int) $config['log_threshold']; - } - elseif (is_array($config['log_threshold'])) - { - $this->_threshold = $this->_threshold_max; - $this->_threshold_array = array_flip($config['log_threshold']); - } - - if ($config['log_date_format'] !== '') - { - $this->_date_fmt = $config['log_date_format']; - } - } - - // -------------------------------------------------------------------- - - /** - * Write Log File - * - * Generally this function will be called using the global log_message() function - * - * @param string the error level - * @param string the error message - * @param bool whether the error is a native PHP error - * @return bool - */ - public function write_log($level = 'error', $msg, $php_error = FALSE) - { - if ($this->_enabled === FALSE) - { - return FALSE; - } - - $level = strtoupper($level); - - if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) - && ! isset($this->_threshold_array[$this->_levels[$level]])) - { - return FALSE; - } - - - $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; - $message = ''; - - if ( ! file_exists($filepath)) - { - $newfile = TRUE; - $message .= '<'."?php defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n"; - } - - if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) - { - return FALSE; - } - - $message .= $level.' '.($level === 'INFO' ? ' -' : '-').' '.date($this->_date_fmt).' --> '.$msg."\n"; - - flock($fp, LOCK_EX); - fwrite($fp, $message); - flock($fp, LOCK_UN); - fclose($fp); - - if (isset($newfile) && $newfile === TRUE) - { - @chmod($filepath, FILE_WRITE_MODE); - } - - return TRUE; - } - -} - -/* End of file Log.php */ -/* Location: ./system/libraries/Log.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b