package com.hammurapi.common.concurrent;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.LogRecord;

/**
 * A wrapper for java.util.logging.Logger
 * @author Pavel Vlasov
 *
 */
public class LoggerWrapper implements Logger {
	
	private java.util.logging.Logger master;

	public void log(LogRecord record) {
		master.log(record);
	}

	public void log(Level level, String msg) {
		master.log(level, msg);
	}

	public void log(Level level, String msg, Object param1) {
		master.log(level, msg, param1);
	}

	public void log(Level level, String msg, Object[] params) {
		master.log(level, msg, params);
	}

	public void log(Level level, String msg, Throwable thrown) {
		master.log(level, msg, thrown);
	}

	public void severe(String msg) {
		master.severe(msg);
	}

	public void warning(String msg) {
		master.warning(msg);
	}

	public void fine(String msg) {
		master.fine(msg);
	}

	public void finer(String msg) {
		master.finer(msg);
	}

	public void finest(String msg) {
		master.finest(msg);
	}

	public boolean isLoggable(Level level) {
		return master.isLoggable(level);
	}

	public LoggerWrapper(java.util.logging.Logger juLogger) {
		this.master = juLogger;
	}

	@Override
	public void info(String msg) {
		master.info(msg);		
	}
	
	private Map<String, Logger> subLoggers = new ConcurrentHashMap<String, Logger>();

	@Override
	public Logger getLogger(String name) {
		Logger ret = subLoggers.get(name);
		if (ret==null) {
			ret = new LoggerWrapper(java.util.logging.Logger.getLogger(master.getName()+"."+name));
			subLoggers.put(name, ret);
		}
		return  ret;
	}


}
