
package com.fuse;

/*
	FUSE Light Server - multiuser server application
	Copyright (C) 2000 Aapo Kyrola / Sulake Oy  Helsinki, Finland

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/



import java.util.Date;
import java.text.*;

public class Log {
	
	public static boolean log_errors = true, log_status = true, log_debug = false;
	private static SimpleDateFormat sdf;
	
	/* To be made more advanced! */
	public static void status(Object o) {
		if (log_status == false) return;
		System.out.println(time() + o.toString());
	}
	
	public static void sometimes(Object o) {
		if (System.currentTimeMillis() % 65 == 0) {
			System.out.println(time() + o.toString());
		}
	}
	
	
	public static void logMemory() {
		System.out.println("freemem=" + Runtime.getRuntime().freeMemory()/1024 + "kb totalmem=" + Runtime.getRuntime().totalMemory()/1024 + "kb");
	}
	
	public static void logMemory(String s) {
		System.out.println(s + ": freemem=" + Runtime.getRuntime().freeMemory()/1024 + "kb totalmem=" + Runtime.getRuntime().totalMemory()/1024 + "kb");
	}
	
	public static void error(Exception e) {
		if (log_errors == false) return;
		status("## ERROR");
		e.printStackTrace();
	}
	
	public static void error(String s) {
		if (log_errors == false) return;
		status("## ERROR: " + s);
	}
	
	public static void debug(Object o) {
		if (log_debug == false) return;
		System.out.println(time() + o.toString());
	}
	
	public static String time() {
		if (sdf == null) sdf = new SimpleDateFormat("dd.MM HH:mm:ss");
		return sdf.format(new Date());
	}
	
	
}