    001package com.hammurapi.common.concurrent;
    002
    003import java.util.Map;
    004import java.util.concurrent.ConcurrentHashMap;
    005import java.util.logging.Level;
    006import java.util.logging.LogRecord;
    007
    008/**
    009 * A wrapper for java.util.logging.Logger
    010 * @author Pavel Vlasov
    011 *
    012 */
    013public class LoggerWrapper implements Logger {
    014
    015        private java.util.logging.Logger master;
    016
    017        public void log(LogRecord record) {
    018                master.log(record);
    019        }
    020
    021        public void log(Level level, String msg) {
    022                master.log(level, msg);
    023        }
    024
    025        public void log(Level level, String msg, Object param1) {
    026                master.log(level, msg, param1);
    027        }
    028
    029        public void log(Level level, String msg, Object[] params) {
    030                master.log(level, msg, params);
    031        }
    032
    033        public void log(Level level, String msg, Throwable thrown) {
    034                master.log(level, msg, thrown);
    035        }
    036
    037        public void severe(String msg) {
    038                master.severe(msg);
    039        }
    040
    041        public void warning(String msg) {
    042                master.warning(msg);
    043        }
    044
    045        public void fine(String msg) {
    046                master.fine(msg);
    047        }
    048
    049        public void finer(String msg) {
    050                master.finer(msg);
    051        }
    052
    053        public void finest(String msg) {
    054                master.finest(msg);
    055        }
    056
    057        public boolean isLoggable(Level level) {
    058                return master.isLoggable(level);
    059        }
    060
    061        public LoggerWrapper(java.util.logging.Logger juLogger) {
    062                this.master = juLogger;
    063        }
    064
    065        @Override
    066        public void info(String msg) {
    067                master.info(msg);
    068        }
    069
    070        private Map<String, Logger> subLoggers = new ConcurrentHashMap<String, Logger>();
    071
    072        @Override
    073        public Logger getLogger(String name) {
    074                Logger ret = subLoggers.get(name);
    075                if (ret==null) {
    076                        ret = new LoggerWrapper(java.util.logging.Logger.getLogger(master.getName()+"."+name));
    077                        subLoggers.put(name, ret);
    078                }
    079                return  ret;
    080        }
    081
    082
    083}