1 23 24 package org.apache.slide.util.logger.jdk14; 25 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 29 33 public class Jdk14Logger implements org.apache.slide.util.logger.Logger { 34 35 public final static int DEFAULT_LEVEL = INFO; 36 37 public Jdk14Logger() { 38 LoggerConfiguration.configure(); 39 } 40 41 public void log(Object data, Throwable throwable, String channel, int slideLevel) { 42 Logger logger = Logger.getLogger(channel); 43 Level level = getLevelForSlideLevel(slideLevel); 44 logger.log(level, data.toString(), throwable); 45 } 46 47 public void log(Object data, String channel, int slideLevel) { 48 Logger logger = Logger.getLogger(channel); 49 Level level = getLevelForSlideLevel(slideLevel); 50 if (data instanceof Throwable ) { 51 logger.log(level, data.toString(), (Throwable ) data); 52 } else { 53 logger.log(level, data.toString()); 54 } 55 } 56 57 public void log(Object data, int level) { 58 this.log(data, DEFAULT_CHANNEL, level); 59 } 60 61 public void log(Object data) { 62 this.log(data, DEFAULT_CHANNEL, DEFAULT_LEVEL); 63 } 64 65 public int getLoggerLevel(String channel) { 66 Logger logger = Logger.getLogger(channel); 67 Level level = logger.getLevel(); 68 return getSlideLevelForLevel(level); 69 } 70 71 public int getLoggerLevel() { 72 return getLoggerLevel(DEFAULT_CHANNEL); 73 } 74 75 public void setLoggerLevel(int slideLevel) { 76 Logger.getLogger("").setLevel(getLevelForSlideLevel(slideLevel)); 77 setLoggerLevel(DEFAULT_CHANNEL, slideLevel); 78 } 79 80 public void setLoggerLevel(String channel, int slideLevel) { 81 Logger logger = Logger.getLogger(channel); 82 Level level = getLevelForSlideLevel(slideLevel); 83 logger.setLevel(level); 84 } 85 86 public boolean isEnabled(String channel, int slideLevel) { 87 Logger logger = Logger.getLogger(channel); 88 Level level = getLevelForSlideLevel(slideLevel); 89 return logger.isLoggable(level); 90 } 91 92 public boolean isEnabled(int level) { 93 return isEnabled(DEFAULT_CHANNEL, level); 94 } 95 96 protected Level getLevelForSlideLevel(int slideLevel) { 97 Level level = Level.ALL; 98 switch (slideLevel) { 99 case EMERGENCY : 100 level = Level.SEVERE; 101 break; 102 case CRITICAL : 103 level = Level.SEVERE; 104 break; 105 case ERROR : 106 level = Level.SEVERE; 107 break; 108 case WARNING : 109 level = Level.WARNING; 110 break; 111 case INFO : 112 level = Level.INFO; 113 break; 114 case DEBUG : 115 level = Level.FINE; 116 break; 117 } 118 return level; 119 } 120 121 protected int getSlideLevelForLevel(Level level) { 122 if (level.equals(Level.ALL)) 123 return DEBUG; 124 if (level.equals(Level.FINEST)) 125 return DEBUG; 126 if (level.equals(Level.FINER)) 127 return DEBUG; 128 if (level.equals(Level.FINE)) 129 return DEBUG; 130 if (level.equals(Level.CONFIG)) 131 return DEBUG; 132 133 if (level.equals(Level.INFO)) 134 return INFO; 135 136 if (level.equals(Level.WARNING)) 137 return WARNING; 138 139 if (level.equals(Level.SEVERE)) 140 return ERROR; 141 142 if (level.equals(Level.OFF)) 143 return -1; 144 145 return DEFAULT_LEVEL; 146 } 147 148 } 149 | Popular Tags |