package de.vsis.groomba.communication;

public class Log {
	
	/**
	 * @author Hannes 
	 * 
	 *  Helps to create different log levels for debugging purposes.
	 *  
	 */
	
	
	public final static int OFF = 0;
	public final static int ERROR = 1;
	public final static int INFO = 2;
	public final static int VERBOSE = 3;
	public final static int DEBUG = 4;
	
	private String _classname = "";
	private boolean _verbose = false;
	private boolean _error = false;
	private boolean _info = false;
	private boolean _debug = false;
	
	public Log() {
		// TODO Auto-generated constructor stub
		setVerbose();
	}
	
	public Log(int level) {
		set(level);
	}

	public Log(String classname) {
		_classname = classname;
	}
	
	public void debug(String msg){
		if(_debug) {
			printLogMsg("debug", msg);
		}
	}
	
	public void log(String msg){
		if (_verbose){
			printLogMsg("verbose", msg);
		}
	}
	
	public void error(String msg){
		if (_error){
			printLogMsg("error", msg);
		}
		
	}
	
	public void info(String msg){
		if (_info){
			printLogMsg("info", msg);
		}
	}
	
	
	/** combine and print to console slave
	 * 
	 * 
	 * @param kind
	 * @param msg
	 */
	private void printLogMsg(String kind, String msg){
		String fullmsg = "";
		if (!_classname.equals("")){
			fullmsg = "["+kind+" from "+_classname+"] --- " + msg;
		}
		else {
			fullmsg = "["+kind+"] --- " + msg;
		}
		
		System.out.println(fullmsg);
	}
	
	
	public void enableAll() {
		_verbose = true;
	}
	
	public void dissableAll() {
		_verbose = false;
	}
	
	public void setVerbose(){
		_verbose = true;
		_error = true;
		_info = true;
		_debug = true;
	}
	
	public void set(int level){
		//0 off, 1 error, 2 info, 3 verbose, 4 Debug(all)
		switch(level){
			case 0:		_verbose = false;
						_error = false;
						_info = false;
						_debug = false;
						break;
					
			case 1: 	_error = true;
						_verbose = false;
						_info = false;
						_debug = false;
						break;
						
			case 2: 	_error = true;
						_info = true;
						_debug = false;
						_verbose = false;
						break;
			
			case 3: 	_verbose = true;
						_error = true;
						_info = true;
						_debug = false;
						break;
			
			case 4: 	setVerbose();
			
			default:	_verbose = true;
						_error = true;
						_info = true;
						_debug = true;
						break;
			}
	}
}
