package com.uas.account.core;

import java.util.LinkedList;
import java.util.List;

import com.uas.account.entity.Log;

public class Logger {

	private static List<Log> logs;

	private static Logger instance;

	public static Logger getLogger() {
		if (instance == null) {
			instance = new Logger();
			logs = new LinkedList<Log>();
		}
		return instance;
	}

	public List<Log> getLogsAndClear() {
		synchronized (logs) {
			List<Log> copy = new LinkedList<Log>(logs);
			logs = new LinkedList<Log>();
			return copy;
		}
	}

	public void info(String msg) {
		info(null, null, msg, null);
	}

	public void info(String msg, Object detailMsg) {
		info(null, null, msg, detailMsg);
	}

	public void info(String key, String msg, Object detailMsg) {
		info(null, key, msg, detailMsg);
	}

	public void info(Class<?> cls, String key, String msg) {
		info(null, key, msg, null);
	}

	public void info(Class<?> cls, String key, String msg, Object detailMsg) {
		synchronized (logs) {
			logs.add(Log.info(cls == null ? null : cls.getName(), key, msg, detailMsg));
		}
	}

	public void warn(String msg) {
		warn(null, null, msg, null);
	}

	public void warn(String msg, Object detailMsg) {
		warn(null, null, msg, detailMsg);
	}

	public void warn(String key, String msg, Object detailMsg) {
		warn(null, key, msg, detailMsg);
	}

	public void warn(Class<?> cls, String key, String msg, Object detailMsg) {
		synchronized (logs) {
			logs.add(Log.warn(cls == null ? null : cls.getName(), key, msg, detailMsg));
		}
	}

	public void error(String msg) {
		error(null, null, msg, null);
	}

	public void error(String msg, Object detailMsg) {
		error(null, null, msg, detailMsg);
	}

	public void error(String key, String msg, Object detailMsg) {
		error(null, key, msg, detailMsg);
	}

	public void error(Class<?> cls, String key, String msg, Object detailMsg) {
		synchronized (logs) {
			logs.add(Log.error(cls == null ? null : cls.getName(), key, msg, detailMsg));
		}
	}
}
