From: Julio G. <ju...@us...> - 2006-02-02 18:02:41
|
Update of /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/logging In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20400/smartfrog/src/org/smartfrog/sfcore/logging Modified Files: LogImpl.java Log Message: Improved error reporting. Index: LogImpl.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/logging/LogImpl.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** LogImpl.java 6 Oct 2005 17:07:08 -0000 1.32 --- LogImpl.java 2 Feb 2006 18:02:33 -0000 1.33 *************** *** 43,46 **** --- 43,47 ---- import java.util.Enumeration; import java.util.Hashtable; + import org.smartfrog.sfcore.common.*; *************** *** 50,56 **** public class LogImpl implements LogSF, LogRegistration, Serializable { - //Configuration for LogImpl class - ComponentDescription classComponentDescription = null; - /** Default Log object */ protected Log localLog = null; --- 51,54 ---- *************** *** 61,64 **** --- 59,64 ---- protected int currentLogLevel= LOG_LEVEL_INFO; + + public static final Method TRACE_O = getObjectMethod("trace", new Class[] {Object.class}); *************** *** 148,165 **** */ public LogImpl (String name){ ! //@TODO: improve error protection logName = name; try { //Check Class and read configuration...including system.properties classComponentDescription = ComponentDescriptionImpl.getClassComponentDescription(this, true,null); ! //Get int from Double ! setLevel (((Number)new Double(classComponentDescription.sfResolve(ATR_LOG_LEVEL,((double)getLevel()),false))).intValue()); ! localLog = getLocalLog(name ! , new Integer(currentLogLevel) ! , (String) classComponentDescription.sfResolve( ! ATR_LOCAL_LOGGER_CLASS ! ,"org.smartfrog.sfcore.logging.LogToFileImpl" ! ,false) ! , getSfCodeBase(classComponentDescription)); //Set lower level of the two, just in case local logger has its own mechanism to set log level int i= getLevel(localLog); --- 148,176 ---- */ public LogImpl (String name){ ! //Configuration for LogImpl class ! ComponentDescription classComponentDescription = null; ! //Configuration for LogImpl class ! ComponentDescription componentComponentDescription = null; ! ! // Level set in configuration ! int configurationLevel = currentLogLevel; ! // logger class set in configuration (Vector or String) ! Object configurationClass = "org.smartfrog.sfcore.logging.LogToFileImpl"; ! // codebase used to load class set in configuration ! String configurationCodeBase = null; ! logName = name; try { + //Check Class and read configuration...including system.properties classComponentDescription = ComponentDescriptionImpl.getClassComponentDescription(this, true,null); ! configurationClass = this.getConfigurationClass(classComponentDescription,configurationClass); ! configurationLevel = this.getConfigurationLevel(classComponentDescription,configurationLevel); ! configurationCodeBase = this.readConfigurationCodeBase(classComponentDescription,configurationCodeBase); ! ! setLevel (configurationLevel); ! ! localLog = getLocalLog(name, new Integer(currentLogLevel), (String)configurationClass, configurationCodeBase); ! //Set lower level of the two, just in case local logger has its own mechanism to set log level int i= getLevel(localLog); *************** *** 168,189 **** } } catch (Exception ex ){ ! String msg = "Error during initialization of localLog for LogImpl. Using Default (LogToFile)"; System.err.println("[WARN] "+msg+", Reason: "+ex.getMessage()); try { localLog=new LogToFileImpl(name,new Integer(currentLogLevel)); ! if (localLog.isWarnEnabled())localLog.warn(msg, ex); } catch (java.lang.NullPointerException nex){ ! msg = "Error during initialization of localLog for LogImpl. No log available."; ! System.err.println("[FATAL] "+msg+", Reason: "+nex.getMessage()); ! nex.printStackTrace(); throw nex; } } ! if (localLog.isTraceEnabled()) { ! localLog.trace("Log '"+name+"' using ComponentDescription:\n"+classComponentDescription.toString()); } } /** * Registered inputs, distribution list */ --- 179,247 ---- } } catch (Exception ex ){ ! String msg = "Error during initialization of localLog for LogImpl. Next trying to using Default (LogToFile)"; ! String msg2 = "Log '"+name+"' , values [class,level,codebase]: "+ configurationClass +", "+ configurationLevel +", "+ configurationCodeBase + ! "\nusing Class ComponentDescription:\n{"+classComponentDescription+ ! "}\n, and using Component ComponentDescription:\n{"+ componentComponentDescription+"}"; ! System.err.println("[WARN] "+msg2); System.err.println("[WARN] "+msg+", Reason: "+ex.getMessage()); try { localLog=new LogToFileImpl(name,new Integer(currentLogLevel)); ! if ((localLog.isWarnEnabled())) localLog.warn(msg2); ! if ((localLog.isWarnEnabled())) localLog.warn(msg, ex); } catch (java.lang.NullPointerException nex){ ! msg = "Error during emergency initialization of localLog using default LogToFile for LogImpl. No logger available."; ! System.err.println("[FATAL] "+msg+", Reason: "+nex.toString()); ! if (org.smartfrog.sfcore.common.Logger.logStackTrace) nex.printStackTrace(); throw nex; } } ! if ((localLog!=null)&&(localLog.isTraceEnabled())) { ! String msg2 = "Log '"+name+"' , values [class,level,codebase]: "+ configurationClass +", "+ configurationLevel +", "+ configurationCodeBase + ! "\nusing Class ComponentDescription:\n {"+classComponentDescription+ ! "}\n, and using Component ComponentDescription:\n{"+ componentComponentDescription+"}"; ! localLog.trace(msg2); } } /** + * Reads configurationClass attribute for LogImpl from a componentDescription + * + * @param componentDescription ComponentDescription + * @param default configurationClass Object + * @return Object (Vector or String) + * @throws SmartFrogResolutionException + */ + private Object getConfigurationClass(ComponentDescription componentDescription, Object configurationClass) throws SmartFrogResolutionException { + if (componentDescription==null) return configurationClass; + return (String)componentDescription.sfResolve( ATR_LOCAL_LOGGER_CLASS, configurationClass, false); + } + + /** + * Reads configurationLevel attribute for LogImpl from a componentDescription + * + * @param componentDescription ComponentDescription + * @param default configurationLevel int + * @return int + * @throws SmartFrogResolutionException + */ + private int getConfigurationLevel(ComponentDescription componentDescription, int configurationLevel) throws SmartFrogResolutionException { + if (componentDescription==null) return configurationLevel; + return componentDescription.sfResolve(ATR_LOG_LEVEL, getLevel(), false); + } + + /** + * Reads configurationCodeBase attribute for LogImpl from a componentDescription + * + * @param componentDescription ComponentDescription + * @param default configurationCodeBase String + * @return String + * @throws SmartFrogResolutionException + */ + private String readConfigurationCodeBase(ComponentDescription componentDescription,String configurationCodeBase) throws SmartFrogResolutionException { + if (componentDescription==null) return configurationCodeBase; + return getSfCodeBase(componentDescription); + } + + /** * Registered inputs, distribution list */ *************** *** 219,224 **** MessageKeys.MSG_ILLEGAL_ACCESS, targetClassName, "newInstance()"), illaexcp); } catch (InvocationTargetException intarexcp) { ! System.out.println("Exllllll: "+intarexcp); ! intarexcp.printStackTrace(); throw new SmartFrogLogException(MessageUtil.formatMessage( MessageKeys.MSG_INVOCATION_TARGET, targetClassName), intarexcp); --- 277,285 ---- MessageKeys.MSG_ILLEGAL_ACCESS, targetClassName, "newInstance()"), illaexcp); } catch (InvocationTargetException intarexcp) { ! String msg = "Error during initialization of localLog for LogImpl."+ ! " Data: name "+name+", targetClassName "+targetClassName+ ! ", logLevel "+logLevel+", targetCodeBase "+targetCodeBase; ! System.err.println("[ERROR] "+msg+", Reason: "+intarexcp.toString()); ! intarexcp.getCause().printStackTrace(); throw new SmartFrogLogException(MessageUtil.formatMessage( MessageKeys.MSG_INVOCATION_TARGET, targetClassName), intarexcp); |