Changeset 1898

Show
Ignore:
Timestamp:
02/01/2008 06:22:27 PM (8 months ago)
Author:
Shadowhand
Message:

Updates to core:

  • Kohana::shutdown, Kohana::exeception_handler updated to provide slightly more more consistent results, in more situations
  • Kohana::exeception handler now disables error reporting after the first error, to prevent errors being reporting during shutdown and causing server/browser errors (Thanks PugFish?)
  • Log::write no longer checks if the output directory is writable. Instead, Kohana::setup makes the check, resulting in detectable "log directory unwritable" errors
Location:
trunk/system
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/core/Kohana.php

    r1886 r1898  
    8585                set_exception_handler(array('Kohana', 'exception_handler')); 
    8686 
    87                 if (Config::item('log.threshold') > 0) 
    88                 { 
    89                         // Enable log writing if the log threshold is above 0 
    90                         register_shutdown_function(array('Log', 'write')); 
    91                 } 
    92  
    9387                // Disable magic_quotes_runtime. The Input library takes care of 
    9488                // magic_quotes_gpc later. 
     
    10094                // Set locale information 
    10195                setlocale(LC_ALL, Config::item('locale.language').'.UTF-8'); 
     96 
     97                if (Config::item('log.threshold') > 0) 
     98                { 
     99                        // Get the configured log directory 
     100                        $log_dir = Config::item('log.directory'); 
     101 
     102                        // Two possible locations 
     103                        $app_log = APPPATH.$log_dir; 
     104                        $log_dir = realpath($log_dir); 
     105 
     106                        // If the log directory does not exist, log inside of application/ 
     107                        is_dir($log_dir) or $log_dir = $app_log; 
     108 
     109                        // Log directory must be writable 
     110                        if ( ! is_dir($log_dir) OR ! is_writable($log_dir)) 
     111                                throw new Kohana_Exception('core.cannot_write_log'); 
     112 
     113                        // Set the log directory 
     114                        Log::directory($log_dir); 
     115 
     116                        // Enable log writing if the log threshold is above 0 
     117                        register_shutdown_function(array('Log', 'write')); 
     118                } 
    102119 
    103120                // Enable Kohana routing 
     
    311328        public static function shutdown() 
    312329        { 
     330                while (ob_get_level() > self::$buffer_level) 
     331                { 
     332                        // Flush all open output buffers above the internal buffer 
     333                        ob_end_flush(); 
     334                } 
     335 
    313336                // This will flush the Kohana buffer, which sets self::$output 
    314337                (ob_get_level() === self::$buffer_level) and ob_end_clean(); 
     
    317340                Event::run('system.display', self::$output); 
    318341 
    319                 // Render the output 
     342                // Render the final output 
    320343                self::render(self::$output); 
    321344        } 
     
    490513                } 
    491514 
    492                 if (ob_get_level() >= self::$buffer_level) 
    493                 { 
    494                         // Flush the entire buffer here, to ensure the error is displayed 
    495                         while(ob_get_level() > self::$buffer_level) ob_end_clean(); 
    496  
    497                         // Clear out the output buffer 
    498                         ob_clean(); 
     515                while (ob_get_level() > self::$buffer_level) 
     516                { 
     517                        // Clean all active output buffers 
     518                        ob_end_clean(); 
    499519                } 
    500520 
     
    526546                // Run the system.shutdown event 
    527547                Event::has_run('system.shutdown') or Event::run('system.shutdown'); 
     548 
     549                // Turn off error reporting 
     550                error_reporting(0); 
    528551                exit; 
    529552        } 
  • trunk/system/core/Log.php

    r1828 r1898  
    1212final class Log { 
    1313 
     14        private static $log_directory; 
     15 
    1416        private static $types = array(1 => 'error', 2 => 'debug', 3 => 'info'); 
    1517        private static $messages = array(); 
     18 
     19        /** 
     20         * Set the the log directory. The log directory is determined by Kohana::setup. 
     21         * 
     22         * @param   string   full log directory path 
     23         * @return  void 
     24         */ 
     25        public static function directory($directory) 
     26        { 
     27                if (self::$log_directory === NULL) 
     28                { 
     29                        // Set the log directory if it has not already been set 
     30                        self::$log_directory = $directory; 
     31                } 
     32        } 
    1633 
    1734        /** 
     
    3855        public static function write() 
    3956        { 
    40                 $filename  = Config::item('log.directory'); 
     57                // Set the log threshold 
    4158                $threshold = Config::item('log.threshold'); 
    4259 
    4360                // Don't log if there is nothing to log to 
    44                 if ($threshold < 1 OR count(self::$messages) == 0 OR $filename == FALSE) return; 
     61                if ($threshold < 1 OR count(self::$messages) === 0) return; 
    4562 
    46                 // Make sure that the log directory is absolute 
    47                 $filename = (substr($filename, 0, 1) === '/') ? $filename : APPPATH.$filename; 
     63                // Set the log filename 
     64                $filename = self::$log_directory.date('Y-m-d').'.log'.EXT; 
    4865 
    49                 // Find the realpath to the log directory 
    50                 $filename = realpath($filename).'/'; 
    51  
    52                 // Make sure the log directory is writable 
    53                 if ( ! is_dir($filename) OR ! is_writable($filename)) 
    54                 { 
    55                         // Disable errors 
    56                         $ER = error_reporting(0); 
    57  
    58                         // Clear the buffer 
    59                         ob_get_level() and ob_clean(); 
    60  
    61                         // Enable errors 
    62                         error_reporting($ER); 
    63  
    64                         exit(Kohana::lang('core.cannot_write_log')); 
    65                 } 
    66  
    67                 // Attach the filename to the directory 
    68                 $filename .= date('Y-m-d').'.log'.EXT; 
    69  
     66                // Compile the messages 
    7067                $messages = ''; 
    71  
    72                 // Get messages 
    7368                foreach(self::$messages as $type => $data) 
    7469                { 
  • trunk/system/libraries/drivers/Database/Mysql.php

    r1895 r1898  
    5959 
    6060                // Build the connection info 
    61                 $host = (isset($host)) ? $host : $socket; 
    62                 $port = (isset($port)) ? ':'.$port : ''; 
     61                $host = isset($host) ? $host : $socket; 
     62                $port = isset($port) ? ':'.$port : ''; 
    6363 
    6464                // Make the connection and select the database