From aae91a45e27cb11e09b22bf9be04a7da9f6ff20b Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:51:30 -0500 Subject: Update system/core/Log.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated Log.php so that a developer can extend it and change the log file extension. It makes sense to default to .php when logs are in the public web folder.  It would be nice if a developer moves the log file path we have the option to use a standard extension like .log --- system/core/Log.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/system/core/Log.php b/system/core/Log.php index f5d091e14..3b0a9213d 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -71,6 +71,13 @@ class CI_Log { * @var string */ protected $_date_fmt = 'Y-m-d H:i:s'; + + /** + * Log file extension + * + * @var string + */ + protected $_log_ext = 'php'; /** * Whether or not the logger can write to the log files @@ -147,7 +154,7 @@ class CI_Log { return FALSE; } - $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_log_ext; $message = ''; if ( ! file_exists($filepath)) @@ -179,4 +186,4 @@ class CI_Log { } /* End of file Log.php */ -/* Location: ./system/core/Log.php */ \ No newline at end of file +/* Location: ./system/core/Log.php */ -- cgit v1.2.3-24-g4f1b From 0bd6b28045c9b9a820e580b3f651f474b60348a3 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 14:16:18 -0500 Subject: Added support for changing the default log file extension from .php to whatever is preferred. example (.log) This is a follow up to this pull request. https://github.com/EllisLab/CodeIgniter/pull/2243 --- application/config/config.php | 11 +++++++++++ system/core/Log.php | 2 ++ user_guide_src/source/changelog.rst | 1 + 3 files changed, 14 insertions(+) diff --git a/application/config/config.php b/application/config/config.php index 415474e06..6f597b1e2 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -224,6 +224,17 @@ $config['log_threshold'] = 0; */ $config['log_path'] = ''; +/* +|-------------------------------------------------------------------------- +| Log File Extension +|-------------------------------------------------------------------------- +| +| Leave this BLANK unless you would like to set something other than the default +| 'php'. For example you could change it to 'log'. +| +*/ +$config['log_file_extension'] = ''; + /* |-------------------------------------------------------------------------- | Date Format for Logs diff --git a/system/core/Log.php b/system/core/Log.php index 3b0a9213d..7572d2ac6 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -104,6 +104,8 @@ class CI_Log { $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; + $this->_log_ext = ($config['log_file_extension'] !== '') ? $config['log_file_extension'] : $this->_log_ext; + file_exists($this->_log_path) OR mkdir($this->_log_path, DIR_WRITE_MODE, TRUE); if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path)) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 893c3db61..7f12ca8a1 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -55,6 +55,7 @@ Release Date: Not Released - Updated *ip_address* database field lengths from 16 to 45 for supporting IPv6 address on :doc:`Trackback Library ` and :doc:`Captcha Helper `. - Removed *cheatsheets* and *quick_reference* PDFs from the documentation. - Added availability checks where usage of dangerous functions like ``eval()`` and ``exec()`` is required. + - Added support for changing the file extension of CodeIgniter log files using $config['log_file_extension']. - Helpers -- cgit v1.2.3-24-g4f1b From 2718f6c8a5bbae38b7a7f875c6eef40739ce8ee4 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Thu, 14 Feb 2013 08:57:49 -0500 Subject: Update system/core/Log.php Added ltrim() as requested to strip '.' incase it's added by mistake. --- system/core/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/core/Log.php b/system/core/Log.php index 7572d2ac6..abc7b2494 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -104,7 +104,7 @@ class CI_Log { $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; - $this->_log_ext = ($config['log_file_extension'] !== '') ? $config['log_file_extension'] : $this->_log_ext; + $this->_log_ext = ($config['log_file_extension'] !== '') ? ltrim($config['log_file_extension'],'.') : $this->_log_ext; file_exists($this->_log_path) OR mkdir($this->_log_path, DIR_WRITE_MODE, TRUE); -- cgit v1.2.3-24-g4f1b From fb8de247990189721bc7b2e48fe57ceb2db039f5 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Thu, 14 Feb 2013 09:01:24 -0500 Subject: Update system/core/Log.php Don't print no script access code into log file if log file is not .php anymore. --- system/core/Log.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/system/core/Log.php b/system/core/Log.php index abc7b2494..7b2082a6c 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -162,7 +162,10 @@ class CI_Log { if ( ! file_exists($filepath)) { $newfile = TRUE; - $message .= '<'."?php defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n"; + if($this->_log_ext === 'php') + { + $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 8d8636778ac600176772c4d54321a1e0842e5b07 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Fri, 15 Feb 2013 09:06:11 -0500 Subject: Update system/core/Log.php Added a space after the comma on the ltrim(). --- system/core/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/core/Log.php b/system/core/Log.php index 7b2082a6c..2a4728dc4 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -104,7 +104,7 @@ class CI_Log { $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; - $this->_log_ext = ($config['log_file_extension'] !== '') ? ltrim($config['log_file_extension'],'.') : $this->_log_ext; + $this->_log_ext = ($config['log_file_extension'] !== '') ? ltrim($config['log_file_extension'], '.') : $this->_log_ext; file_exists($this->_log_path) OR mkdir($this->_log_path, DIR_WRITE_MODE, TRUE); -- cgit v1.2.3-24-g4f1b From ce6f43b7120a184aa0cff0bdb90fa3d7f032e14b Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Tue, 12 Feb 2013 16:58:38 -0500 Subject: Update system/core/Common.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If using nginx instead of apache by default nginx will not populate the $_SERVER['HTTPS'] value.  This change allows falling back to checking the port number of the request to determine if your on SSL or not. The other option is adding the following to your nginx config. fastcgi_param HTTPS on; #some php apps require this to detent https --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index 258cd4967..b9c872748 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -343,7 +343,7 @@ if ( ! function_exists('is_https')) */ function is_https() { - return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); + return ( ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) || ($_SERVER["SERVER_PORT"] === '443') ); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ \ No newline at end of file +/* Location: ./system/core/Common.php */ -- cgit v1.2.3-24-g4f1b From 614cc1c384b84801428f9823007586584af00653 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:45:20 -0500 Subject: Revert "Update system/core/Common.php" This reverts commit 8af05ac97513764cc539919e179794df87352c30. --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index b9c872748..258cd4967 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -343,7 +343,7 @@ if ( ! function_exists('is_https')) */ function is_https() { - return ( ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) || ($_SERVER["SERVER_PORT"] === '443') ); + return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ +/* Location: ./system/core/Common.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b0607703b32ec790cc300e9f77a18ea17ab6d7dd Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:47:02 -0500 Subject: Revert "Revert "Update system/core/Common.php"" This reverts commit 3de57eaea8510ea9cfd70f063565c24904669c4c. --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index 258cd4967..b9c872748 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -343,7 +343,7 @@ if ( ! function_exists('is_https')) */ function is_https() { - return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); + return ( ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) || ($_SERVER["SERVER_PORT"] === '443') ); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ \ No newline at end of file +/* Location: ./system/core/Common.php */ -- cgit v1.2.3-24-g4f1b From 6f19fd770b67804797c55d47c1c5f5fcb3a37b2e Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:47:02 -0500 Subject: Revert "Update system/core/Log.php" This reverts commit bbc6ab4736a896be83e3e3d5f8856374ffa2984c. --- system/core/Log.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/system/core/Log.php b/system/core/Log.php index 2a4728dc4..0749de8ba 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -71,13 +71,6 @@ class CI_Log { * @var string */ protected $_date_fmt = 'Y-m-d H:i:s'; - - /** - * Log file extension - * - * @var string - */ - protected $_log_ext = 'php'; /** * Whether or not the logger can write to the log files @@ -156,7 +149,7 @@ class CI_Log { return FALSE; } - $filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_log_ext; + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; $message = ''; if ( ! file_exists($filepath)) @@ -191,4 +184,4 @@ class CI_Log { } /* End of file Log.php */ -/* Location: ./system/core/Log.php */ +/* Location: ./system/core/Log.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 62f7cdf3a6f5d701430267ef9ba9bfd92650deab Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:47:45 -0500 Subject: Revert "Update system/core/Common.php" This reverts commit 8af05ac97513764cc539919e179794df87352c30. --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index b9c872748..258cd4967 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -343,7 +343,7 @@ if ( ! function_exists('is_https')) */ function is_https() { - return ( ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) || ($_SERVER["SERVER_PORT"] === '443') ); + return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ +/* Location: ./system/core/Common.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b