<?php

namespace Core;

class Log
{
	var $history = array();
	var $suffix = 'y_m_d';
	
	function write($message, $target = null)
	{
		global $ROOT;
		if (!isset($target)) $target = "default";
		if (($message = trim($message)) == false) return;
		$path = $ROOT . "log/";
		$file = $path . $target . (empty($this->suffix) ? '' : (strlen($target) ? "-" : "") . date($this->suffix)) . ".log";
		$stamp = \Core\Clock::getCurrentStamp();
		$this->history[$target] = $stamp . "\t" . $message;
		$remote = $_SERVER['REMOTE_ADDR'] . ":" . $_SERVER['REMOTE_PORT'];
		$line = $stamp . "\t" . $remote . "\t" . $message . "\r\n";
		file_put_contents($file, $line, FILE_APPEND | LOCK_EX);
	}
}
