1 64 65 package com.jcorporate.expresso.core.controller; 66 67 import com.jcorporate.expresso.kernel.InstallLog; 68 import org.apache.log4j.Logger; 69 70 import java.io.ByteArrayOutputStream ; 71 import java.io.PrintStream ; 72 73 94 public class ControllerInstallLog implements InstallLog { 95 96 protected ControllerResponse response; 97 protected Block parentBlock; 98 99 private static final transient Logger log = Logger.getLogger(ControllerInstallLog.class); 100 101 107 public ControllerInstallLog(ControllerResponse theResponse) { 108 response = theResponse; 109 parentBlock = null; 110 } 111 112 115 protected ControllerInstallLog() { 116 117 } 118 119 126 public void setParentBlock(Block b) { 127 parentBlock = b; 128 } 129 130 136 protected void addOutput(Output logMessage) { 137 try { 138 if (parentBlock == null) { 139 response.add(logMessage); 140 } else { 141 parentBlock.add(logMessage); 142 } 143 } catch (ControllerException ex) { 144 log.warn("Error logging install message", ex); 145 } 146 } 147 148 149 154 public void debug(String message) { 155 Output o = new Output("[DEBUG] " + message); 156 o.setAttribute("color", "green"); 157 addOutput(o); 158 } 159 160 161 166 public void info(String message) { 167 Output o = new Output(message); 168 o.setAttribute("color", "black"); 169 addOutput(o); 170 } 171 172 177 public void warn(String message) { 178 Output o = new Output("[WARN] " + message); 179 o.setAttribute("color", "orange"); 180 addOutput(o); 181 } 182 183 189 public void warn(String message, Throwable error) { 190 Output o = new Output("[WARN] " + message); 191 o.setAttribute("color", "orange"); 192 addNestedOutputs(o, error); 193 addOutput(o); 194 } 195 196 202 public void error(String message, Throwable error) { 203 Output o = new Output("[ERROR] " + message); 204 o.setAttribute("color", "red"); 205 addNestedOutputs(o, error); 206 addOutput(o); 207 } 208 209 214 public void error(String message) { 215 Output o = new Output("[ERROR] " + message); 216 o.setAttribute("color", "red"); 217 addOutput(o); 218 } 219 220 221 227 protected void addNestedOutputs(Output o, Throwable error) { 228 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 229 error.printStackTrace(new PrintStream (bos)); 230 o.addNested(new Output("stackTrace", bos.toString())); 231 o.addNested(new Output("errorMessage", error.getMessage())); 232 } 233 } | Popular Tags |