<?php

$_log_is_in_inline = false;

function _log($string) {
	global $_log_is_in_inline;
	if ($_log_is_in_inline) {
		// line feed now
		_log_inline(PHP_EOL);
	}

	$string = date('H:i:s') . " " . $string . PHP_EOL;
	_log_impl($string);

	$_log_is_in_inline = false;
}

function _log_inline($string) {
	global $_log_is_in_inline;

	if (!$_log_is_in_inline) {
		$string = date('H:i:s') . " " . $string;
	}
	_log_impl($string);

	$_log_is_in_inline = true;
}

function _log_impl($string) {
	global $_log_file;
	global $_debug_output;

	if ($_debug_output) {
		echo $string;
	}

	// write to file too
	if ($_log_file != "") {
		file_put_contents($_log_file, $string, FILE_APPEND);
	}
}

?>