Kohana_Log_File
Kohana_Log_Writer

Class Contents

Constants

  • None

Properties

  • None

Class declared in SYSPATH/classes/kohana/log/file.php on line 11.

Methods

public __construct( )
Kohana_Log_File

Source Code
public function __construct($directory)
{
	if ( ! is_dir($directory) OR ! is_writable($directory))
	{
		throw new Kohana_Exception('Directory :dir must be writable',
			array(':dir' => Kohana::debug_path($directory)));
	}

	// Determine the directory path
	$this->_directory = realpath($directory).DIRECTORY_SEPARATOR;
}

public write( )
Kohana_Log_File

Source Code
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 yearly 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);
	}

	// Set the log line format
	$format = 'time --- type: body';

	foreach ($messages as $message)
	{
		// Write each message into the log file
		file_put_contents($filename, PHP_EOL.strtr($format, $message), FILE_APPEND);
	}
}

final public __toString( )
Kohana_Log_Writer

Source Code
final public function __toString()
{
	return spl_object_hash($this);
}