/** * Deletes old log files older than # days defined in config */ public function remove_old_logs() { $days_old = Kohana::config('config.log_cleanup_days_old'); // First check if we should even be doing this if ($days_old == FALSE or !is_int($days_old)) { return FALSE; } $dir = Kohana::log_directory(); if (is_dir($dir) and is_writable($dir) and $dh = opendir($dir)) { $oldest_allowed = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $days_old, date("Y"))); while (($file = readdir($dh)) !== false) { // If it's a hidden or system file, skip it if ($file[0] == '.') { continue; } // Strip off the file extension so we can just evaluate the date $date = str_ireplace('.log' . EXT, '', $file); if ($date <= $oldest_allowed) { // This file needs to be deleted. unlink($dir . $file); } } closedir($dh); } //$filename = $dir.date('Y-m-d').'.log'.EXT; //var_dump($filename); }
protected function submitReport($report) { $valid = TRUE; $validation = Bluebox_Controller::$validation; if (empty($report['issue'])) { $validation->add_error('report[issue]', 'Please describe the issue'); $valid = FALSE; } if (empty($report['while'])) { $validation->add_error('report[while]', 'Please describe the cause'); $valid = FALSE; } if (empty($report['contact'])) { $validation->add_error('report[contact]', 'Please provide a method to contact you'); $valid = FALSE; } if (empty($report['error'])) { $validation->add_error('report[error]', 'Please provide the error message'); $valid = FALSE; } if (!$valid) { return FALSE; } if (!empty($report['log'])) { $filename = Kohana::log_directory() . date('Y-m-d') . '.log' . EXT; $offset = -150 * 120; $rs = @fopen($filename, 'r'); $report['log'] = ''; if ($rs !== FALSE) { fseek($rs, $offset, SEEK_END); fgets($rs); while (!feof($rs)) { $buffer = fgets($rs); $report['log'] .= htmlspecialchars($buffer . "\n"); } fclose($rs); } } $allowStats = Kohana::config('core.anonymous_statistics'); if (!empty($allowStats)) { $report['anonymous_id'] = Kohana::config('core.anonymous_id'); Package_Catalog::disableRemote(); Package_Catalog::buildCatalog(); $report['catalog'] = Package_Catalog::getPackageList(); } try { $errorCollector = Kohana::config('errorreporter.collector'); $this->do_post_request($errorCollector, $report); } catch (Exception $e) { message::set($e->getMessage()); $this->returnQtipAjaxForm(NULL); return FALSE; } return TRUE; }
/** * Implements the deletion of old logs if the indicia.log_rotate config item exists * @throws \Kohana_Exception */ public static function log_rotate() { $rotate_days = Kohana::config('indicia.log_rotate', FALSE, FALSE); if ($rotate_days) { $filename = Kohana::log_directory() . date('Y-m-d') . '.log' . EXT; if (!is_file($filename)) { // writing the first message today, so we can go back and delete log files over a certain age $files = glob(Kohana::log_directory() . "*"); $now = time(); foreach ($files as $file) { if (is_file($file) && $now - filemtime($file) >= 60 * 60 * 24 * $rotate_days) { unlink($file); } } } } }
public static function changeDebugLevel($new_level = NULL) { // If the users debug_level is valid then update our threshold and // re-init the kohana logger so it takes the new settings if ($new_level <= 4 and $new_level >= 0) { $old_level = Kohana::config('core.log_threshold'); Kohana::config_set('core.log_threshold', $new_level); Kohana::log_directory(Kohana::config('core.log_directory')); register_shutdown_function(array('Kohana', 'log_save')); Event::run('bluebox.change_debug_level', $new_level); return TRUE; } return FALSE; }