001 package org.shiftone.jrat.util.log.target;
002
003
004 import org.shiftone.jrat.util.log.Constants;
005
006
007 /**
008 * This class is an indirection layer to the "real" LogTarget. This makes it
009 * possible to switch the LogTarget that is being used by many LogTargetLog
010 * instances in one statement.
011 *
012 * @author jeff@shiftone.org (Jeff Drost)
013 */
014 public class ProxyLogTarget implements LogTarget, Constants {
015
016 private LogTarget logTarget;
017 private int currentLevel = DEFAULT_LEVEL;
018
019 public ProxyLogTarget(LogTarget logTarget) {
020 this.logTarget = logTarget;
021 }
022
023
024 public boolean isLevelEnabled(String topic, int level) {
025 return (level >= currentLevel);
026 }
027
028
029 public LogTarget getLogTarget() {
030 return logTarget;
031 }
032
033
034 public void setLogTarget(LogTarget logTarget) {
035 this.logTarget = logTarget;
036 }
037
038
039 public int getCurrentLevel() {
040 return currentLevel;
041 }
042
043
044 public void setCurrentLevel(int currentLevel) {
045 this.currentLevel = currentLevel;
046 }
047
048
049 public void log(String topic, int level, Object message, Throwable throwable) {
050
051 if (isLevelEnabled(topic, level)) {
052 logTarget.log(topic, level, message, throwable);
053 }
054 }
055 }