Upgrade to KH 3.3.0

This commit is contained in:
Deon George
2012-11-22 14:25:06 +11:00
parent e5e67a59bb
commit 5bd1841571
1455 changed files with 114353 additions and 9466 deletions

View File

@@ -0,0 +1,94 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* File log writer. Writes out messages and stores them in a YYYY/MM directory.
*
* @package Kohana
* @category Logging
* @author Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Log_File extends Log_Writer {
/**
* @var string Directory to place log files in
*/
protected $_directory;
/**
* Creates a new file logger. Checks that the directory exists and
* is writable.
*
* $writer = new Log_File($directory);
*
* @param string $directory log directory
* @return void
*/
public function __construct($directory)
{
if ( ! is_dir($directory) OR ! is_writable($directory))
{
throw new Kohana_Exception('Directory :dir must be writable',
array(':dir' => Debug::path($directory)));
}
// Determine the directory path
$this->_directory = realpath($directory).DIRECTORY_SEPARATOR;
}
/**
* Writes each of the messages into the log file. The log file will be
* appended to the `YYYY/MM/DD.log.php` file, where YYYY is the current
* year, MM is the current month, and DD is the current day.
*
* $writer->write($messages);
*
* @param array $messages
* @return void
*/
public function write(array $messages)
{
// Set the yearly directory name
$directory = $this->_directory.date('Y');
if ( ! is_dir($directory))
{
// Create the yearly directory
mkdir($directory, 02777);
// Set permissions (must be manually set to fix umask issues)
chmod($directory, 02777);
}
// Add the month to the directory
$directory .= DIRECTORY_SEPARATOR.date('m');
if ( ! is_dir($directory))
{
// Create the monthly directory
mkdir($directory, 02777);
// Set permissions (must be manually set to fix umask issues)
chmod($directory, 02777);
}
// Set the name of the log file
$filename = $directory.DIRECTORY_SEPARATOR.date('d').EXT;
if ( ! file_exists($filename))
{
// Create the log file
file_put_contents($filename, Kohana::FILE_SECURITY.' ?>'.PHP_EOL);
// Allow anyone to write to log files
chmod($filename, 0666);
}
foreach ($messages as $message)
{
// Write each message into the log file
file_put_contents($filename, PHP_EOL.$this->format_message($message), FILE_APPEND);
}
}
} // End Kohana_Log_File

View File

@@ -0,0 +1,29 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* STDERR log writer. Writes out messages to STDERR.
*
* @package Kohana
* @category Logging
* @author Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaphp.com/license
*/
class Kohana_Log_StdErr extends Log_Writer {
/**
* Writes each of the messages to STDERR.
*
* $writer->write($messages);
*
* @param array $messages
* @return void
*/
public function write(array $messages)
{
foreach ($messages as $message)
{
// Writes out each message
fwrite(STDERR, $this->format_message($message).PHP_EOL);
}
}
} // End Kohana_Log_StdErr

View File

@@ -0,0 +1,30 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* STDOUT log writer. Writes out messages to STDOUT.
*
* @package Kohana
* @category Logging
* @author Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaphp.com/license
*/
class Kohana_Log_StdOut extends Log_Writer {
/**
* Writes each of the messages to STDOUT.
*
* $writer->write($messages);
*
* @param array $messages
* @return void
*/
public function write(array $messages)
{
foreach ($messages as $message)
{
// Writes out each message
fwrite(STDOUT, $this->format_message($message).PHP_EOL);
}
}
} // End Kohana_Log_StdOut

View File

@@ -0,0 +1,65 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Syslog log writer.
*
* @package Kohana
* @category Logging
* @author Jeremy Bush
* @copyright (c) 2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Log_Syslog extends Log_Writer {
/**
* @var string The syslog identifier
*/
protected $_ident;
/**
* Creates a new syslog logger.
*
* @link http://www.php.net/manual/function.openlog
*
* @param string $ident syslog identifier
* @param int $facility facility to log to
* @return void
*/
public function __construct($ident = 'KohanaPHP', $facility = LOG_USER)
{
$this->_ident = $ident;
// Open the connection to syslog
openlog($this->_ident, LOG_CONS, $facility);
}
/**
* Writes each of the messages into the syslog.
*
* @param array $messages
* @return void
*/
public function write(array $messages)
{
foreach ($messages as $message)
{
syslog($message['level'], $message['body']);
if (isset($message['additional']['exception']))
{
syslog(Log_Writer::$strace_level, $message['additional']['exception']->getTraceAsString());
}
}
}
/**
* Closes the syslog connection
*
* @return void
*/
public function __destruct()
{
// Close connection to syslog
closelog();
}
} // End Kohana_Log_Syslog

View File

@@ -0,0 +1,95 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Log writer abstract class. All [Log] writers must extend this class.
*
* @package Kohana
* @category Logging
* @author Kohana Team
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
abstract class Kohana_Log_Writer {
/**
* @var string timestamp format for log entries.
*
* Defaults to Date::$timestamp_format
*/
public static $timestamp;
/**
* @var string timezone for log entries
*
* Defaults to Date::$timezone, which defaults to date_default_timezone_get()
*/
public static $timezone;
/**
* Numeric log level to string lookup table.
* @var array
*/
protected $_log_levels = array(
LOG_EMERG => 'EMERGENCY',
LOG_ALERT => 'ALERT',
LOG_CRIT => 'CRITICAL',
LOG_ERR => 'ERROR',
LOG_WARNING => 'WARNING',
LOG_NOTICE => 'NOTICE',
LOG_INFO => 'INFO',
LOG_DEBUG => 'DEBUG',
);
/**
* @var int Level to use for stack traces
*/
public static $strace_level = LOG_DEBUG;
/**
* Write an array of messages.
*
* $writer->write($messages);
*
* @param array $messages
* @return void
*/
abstract public function write(array $messages);
/**
* Allows the writer to have a unique key when stored.
*
* echo $writer;
*
* @return string
*/
final public function __toString()
{
return spl_object_hash($this);
}
/**
* Formats a log entry.
*
* @param array $message
* @param string $format
* @return string
*/
public function format_message(array $message, $format = "time --- level: body in file:line")
{
$message['time'] = Date::formatted_time('@'.$message['time'], Log_Writer::$timestamp, Log_Writer::$timezone, TRUE);
$message['level'] = $this->_log_levels[$message['level']];
$string = strtr($format, $message);
if (isset($message['additional']['exception']))
{
// Re-use as much as possible, just resetting the body to the trace
$message['body'] = $message['additional']['exception']->getTraceAsString();
$message['level'] = $this->_log_levels[Log_Writer::$strace_level];
$string .= PHP_EOL.strtr($format, $message);
}
return $string;
}
} // End Kohana_Log_Writer