1 package org.sapia.taskman; 2 3 21 public class DefaultTaskOutput implements TaskOutput { 22 26 public static int DEBUG = 0; 27 28 32 public static int INFO = 1; 33 34 38 public static int WARNING = 2; 39 40 44 public static int ERROR = 3; 45 46 51 public static final String [] LEVEL = new String [] { "debug", "info", 52 "warning", "error" }; 53 private int _lvl; 54 protected String _taskName; 55 56 59 public DefaultTaskOutput(String taskName, int level) { 60 _lvl = level; 61 _taskName = taskName; 62 } 63 64 67 public void setTaskName(String name) { 68 _taskName = name; 69 } 70 71 74 public TaskOutput debug(Object message) { 75 if(DEBUG >= _lvl) { 76 doOutput(DEBUG, message, null); 77 } 78 79 return this; 80 } 81 82 85 public TaskOutput error(Object message, Throwable t) { 86 if(ERROR >= _lvl) { 87 doOutput(ERROR, message, t); 88 } 89 90 return this; 91 } 92 93 96 public TaskOutput error(Object message) { 97 if(ERROR >= _lvl) { 98 doOutput(ERROR, message, null); 99 } 100 101 return this; 102 } 103 104 107 public TaskOutput error(Throwable t) { 108 if(ERROR >= _lvl) { 109 doOutput(t); 110 } 111 112 return this; 113 } 114 115 118 public TaskOutput info(Object message) { 119 if(INFO >= _lvl) { 120 doOutput(INFO, message, null); 121 } 122 123 return this; 124 } 125 126 129 public TaskOutput warning(Object message) { 130 if(WARNING >= _lvl) { 131 doOutput(WARNING, message, null); 132 } 133 134 return this; 135 } 136 137 143 public void close() { 144 } 145 146 151 protected String getTaskName() { 152 return _taskName; 153 } 154 155 160 protected String getLevelNameFor(int priority) { 161 return LEVEL[priority]; 162 } 163 164 184 protected void doOutput(int lvl, Object message, Throwable t) { 185 System.out.print("["); 186 System.out.print(_taskName); 187 System.out.print(" - "); 188 System.out.print(LEVEL[lvl]); 189 System.out.print("]"); 190 System.out.println(message); 191 192 if(t != null) { 193 t.printStackTrace(); 194 } 195 } 196 197 204 protected void doOutput(Throwable t) { 205 System.out.print("["); 206 System.out.print(_taskName); 207 System.out.print(" - "); 208 System.out.print(LEVEL[ERROR]); 209 System.out.print("]"); 210 System.out.println(); 211 t.printStackTrace(); 212 } 213 } 214 | Popular Tags |