<?php
class Log {
	private $filename;

	public function __construct($filename) {
		$this->filename = $filename;
	}

	public function write($message) {
		$file = DIR_LOGS . date('Y-m-d').'_'.$this->filename;

		$handle = fopen($file, 'a+');
		$date = new DateTime();

		if (is_array($message) || is_object($message)) {
			$string_log = json_encode($message, JSON_UNESCAPED_UNICODE);
		} else {
			$string_log = (string)$message;
		}
		
		fwrite($handle, $date->format('Y-m-d G:i:s.v') .  ' - ' . $string_log . "\n");

		fclose($handle);
	}
}
