<?php

class LogLevel {
	
	const Debug   = "DEBUG  ";
	const Verbose = "VERBOSE";
	const Warning = "WARNING";
	const Error   = "ERROR  ";
	
}

class Log {
	
	public static function d($msg, $logtag="phonalisa-webinterface") {
		Log::writeLog($msg, $logtag, LogLevel::Debug);
	}

	public static function v($msg, $logtag="phonalisa-webinterface") {
		Log::writeLog($msg, $logtag, LogLevel::Verbose);
	}
	
	public static function w($msg, $logtag="phonalisa-webinterface") {
		Log::writeLog($msg, $logtag, LogLevel::Warning);
	}
	
	public static function e($msg, $logtag="phonalisa-webinterface") {
		Log::writeLog($msg, $logtag, LogLevel::Error);
	}
	
	private static function writeLog($msg, $logtag, $level)
	{

		$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
		if (!$socket) {
			return;
		}
		
		$sendMessage = $level.chr(04).$logtag.chr(04).$msg;
		socket_sendto($socket, $sendMessage, strlen($sendMessage), 0, Yii::app()->params['logServer'], Yii::app()->params['logServerPort']);
	}
	
	
	
}