List of usage examples for org.apache.commons.logging Log isTraceEnabled
boolean isTraceEnabled();
From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java
/** * Logs the given message to the log at the trace level. If the log level is not enabled, this method does * nothing and returns <code>null</code>. If a message was logged, its {@link Msg} will be returned. * * <p>The given Throwable will be passed to the logger so its stack can be dumped when appropriate.</p> * * @param log the log where the messages will go * @param throwable the throwable associated with the log message * @param basename the base name of the resource bundle * @param locale the locale to determine what bundle to use * @param key the resource bundle key name * @param varargs arguments to help fill in the resource bundle message * * @return if the message was logged, a non-<code>null</code> Msg object is returned */// ww w . j a v a 2 s . c o m public static Msg trace(Log log, Throwable throwable, BundleBaseName basename, Locale locale, String key, Object... varargs) { if (log.isTraceEnabled()) { Msg msg = Msg.createMsg(basename, locale, key, varargs); logTraceWithThrowable(log, key, msg, throwable); return msg; } return null; }
From source file:net.sf.jabb.util.ex.LoggedException.java
/** * Create a new instance, and at the same time, ensure the original exception is logged. * //from ww w. j av a 2s. c o m * @param log the log utility * @param level level of the log * @param message description * @param cause the original exception. If it is of type LoggedException, * then the newly created instance is a clone of itself. */ public LoggedException(Log log, int level, String message, Throwable cause) { super(cause instanceof LoggedException ? cause.getMessage() : message, cause instanceof LoggedException ? cause.getCause() : cause); if (!(cause instanceof LoggedException)) { switch (level) { case TRACE: if (log.isTraceEnabled()) { log.trace(message, cause); } break; case DEBUG: if (log.isDebugEnabled()) { log.debug(message, cause); } break; case WARN: if (log.isWarnEnabled()) { log.warn(message, cause); } break; case FATAL: log.fatal(message, cause); break; case INFO: log.info(message, cause); break; default: log.error(message, cause); } } }
From source file:net.sf.nmedit.jtheme.store2.AbstractMultiParameterElement.java
protected void link(JTComponent component, PModule module) { if (bindings == null) throw new UnsupportedOperationException(); for (int i = 0; i < parameterElementNames.length; i++) { String name = parameterElementNames[i]; PParameter param = module.getParameterByComponentId(componentIdList[i]); if (param != null) { // set adapter Method setter = bindings.getAdapterSetter(name); int index = bindings.getAdapterSetterIndex(name); try { JTParameterControlAdapter adapter = new JTParameterControlAdapter(param); if (index < 0) { // one arg Object[] args = new Object[] { adapter }; setter.invoke(component, args); PParameter extParam = param.getExtensionParameter(); if (extParam != null) { JTParameterControlAdapter extParamAdapt = new JTParameterControlAdapter(extParam); Method setterExt = bindings.getAdapterSetter(name + "Extension"); Object[] argsExt = new Object[] { extParamAdapt }; if (setterExt != null) setterExt.invoke(component, argsExt); else { // TODO: detect which component don't handle morph // for example: curves //System.out.println(extParam.getName()+" "+component); }/*from ww w . ja va 2s. co m*/ } } else { // several args Object[] args = new Object[] { index, adapter }; setter.invoke(component, args); PParameter extParam = param.getExtensionParameter(); if (extParam != null) { JTParameterControlAdapter extParamAdapt = new JTParameterControlAdapter(extParam); String extName; if (index > 9) { extName = name.substring(0, name.length() - 2) + "Extension" + index; } else { extName = name.substring(0, name.length() - 1) + "Extension" + index; } Method setterExt = bindings.getAdapterSetter(extName); Object[] argsExt = new Object[] { index, extParamAdapt }; if (setterExt != null) { setterExt.invoke(component, argsExt); } else { // TODO: detect which component don't handle morph // for example: curves //System.out.println(extParam.getName()+" "+component); } } } } catch (Throwable t) { Log log = LogFactory.getLog(getClass()); if (log.isTraceEnabled()) { log.trace("error in link(" + component + "," + module + ")", t); } } } else { // log: parameter not found } } if (valueList != null) { for (int i = 0; i < valueList.length; i += 2) { String name = (String) valueList[i]; Integer value = (Integer) valueList[i + 1]; if (value != null) { Method setter = bindings.getValueSetter(name); try { setter.invoke(component, new Object[] { value }); } catch (Exception e) { Log log = LogFactory.getLog(getClass()); if (log.isTraceEnabled()) { log.trace("error in link(" + component + "," + module + ")", e); } } } } } }
From source file:gov.nih.nci.cabig.caaers.tools.logging.CaaersLoggingAspect.java
@Around("execution(public * gov.nih.nci.cabig.caaers.api.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.api.impl.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.dao..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.domain.repository.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.domain.repository.ajax.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.service..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.validation..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.workflow..*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.rules.business.service.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.rules.runtime.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.ae.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.study.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.admin.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.rule.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.web.participant.*.*(..))" + "|| execution(public * gov.nih.nci.cabig.caaers.tools.Excel*.*(..))") public Object log(ProceedingJoinPoint call) throws Throwable { Log logger = (call.getTarget() == null) ? LogFactory.getLog(CaaersLoggingAspect.class) : LogFactory.getLog(call.getTarget().getClass()); //just proceed to call if Info is not enabled. if (logger == null || !logger.isInfoEnabled()) return call.proceed(); boolean traceEnabled = logger.isTraceEnabled(); String userName = ""; if (traceEnabled) { userName = "[" + getUserLoginName() + "] - "; log(logger, true, call, null, 0, userName); }/*w ww . j a v a 2s.c o m*/ long startTime = System.currentTimeMillis(); //proceed with the call Object point = call.proceed(); long endTime = System.currentTimeMillis(); long executionTime = (endTime - startTime); if (executionTime > 500) { logger.info(userName + "More than 500ms [ " + call.toShortString() + " executionTime : " + executionTime + "]"); } if (traceEnabled) { log(logger, false, call, point, executionTime, userName); } return point; }
From source file:eu.qualityontime.commons.MethodUtils.java
/** * <p>// ww w . j ava 2 s .c o m * Find an accessible method that matches the given name and has compatible * parameters. Compatible parameters mean that every method parameter is * assignable from the given parameters. In other words, it finds a method * with the given name that will take the parameters given. * </p> * * <p> * This method is slightly undeterministic since it loops through methods * names and return the first matching method. * </p> * * <p> * This method is used by * {@link #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}. * * <p> * This method can match primitive parameter by passing in wrapper classes. * For example, a <code>Boolean</code> will match a primitive * <code>boolean</code> parameter. * * @param clazz * find method in this class * @param methodName * find method with this name * @param parameterTypes * find method with compatible parameters * @return The accessible method */ public static Method getMatchingAccessibleMethod(final Class<?> clazz, final String methodName, final Class<?>[] parameterTypes) { // trace logging final Log log = LogFactory.getLog(MethodUtils.class); if (log.isTraceEnabled()) { log.trace("Matching name=" + methodName + " on " + clazz); } final MethodDescriptor md = new MethodDescriptor(clazz, methodName, parameterTypes, false); // see if we can find the method directly // most of the time this works and it's much faster try { // Check the cache first Method method = getCachedMethod(md); if (method != null) { return method; } method = clazz.getMethod(methodName, parameterTypes); if (log.isTraceEnabled()) { log.trace("Found straight match: " + method); log.trace("isPublic:" + Modifier.isPublic(method.getModifiers())); } setMethodAccessible(method); // Default access superclass workaround cacheMethod(md, method); return method; } catch (final NoSuchMethodException e) { /* SWALLOW */ } // search through all methods final int paramSize = parameterTypes.length; Method bestMatch = null; final Method[] methods = clazz.getMethods(); float bestMatchCost = Float.MAX_VALUE; float myCost = Float.MAX_VALUE; for (final Method method2 : methods) { if (method2.getName().equals(methodName)) { // log some trace information if (log.isTraceEnabled()) { log.trace("Found matching name:"); log.trace(method2); } // compare parameters final Class<?>[] methodsParams = method2.getParameterTypes(); final int methodParamSize = methodsParams.length; if (methodParamSize == paramSize) { boolean match = true; for (int n = 0; n < methodParamSize; n++) { if (log.isTraceEnabled()) { log.trace("Param=" + parameterTypes[n].getName()); log.trace("Method=" + methodsParams[n].getName()); } if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) { if (log.isTraceEnabled()) { log.trace(methodsParams[n] + " is not assignable from " + parameterTypes[n]); } match = false; break; } } if (match) { // get accessible version of method final Method method = getAccessibleMethod(clazz, method2); if (method != null) { if (log.isTraceEnabled()) { log.trace(method + " accessible version of " + method2); } setMethodAccessible(method); // Default access // superclass // workaround myCost = getTotalTransformationCost(parameterTypes, method.getParameterTypes()); if (myCost < bestMatchCost) { bestMatch = method; bestMatchCost = myCost; } } log.trace("Couldn't find accessible method."); } } } } if (bestMatch != null) { cacheMethod(md, bestMatch); } else { // didn't find a match log.trace("No match found."); } return bestMatch; }
From source file:com.googlecode.jcimd.PacketSerializer.java
private static Packet doDeserializePacket(InputStream inputStream, int maxMessageSize, boolean useChecksum, Log logger) throws IOException { ByteArrayOutputStream temp = new ByteArrayOutputStream(); int b;/*ww w .j a va2s .c om*/ while ((b = inputStream.read()) != END_OF_STREAM) { // Any data transmitted between packets SHALL be ignored. if (b == STX) { temp.write(b); break; } } if (b != STX) { //throw new SoftEndOfStreamException(); throw new IOException("End of stream reached and still no <STX> byte"); } // Read the input stream until ETX while ((b = inputStream.read()) != END_OF_STREAM) { temp.write(b); if (b == ETX) { break; } if (temp.size() >= maxMessageSize) { // Protect from buffer overflow throw new IOException( "Buffer overflow reached at " + temp.size() + " byte(s) and still no <ETX> byte"); } } if (b != ETX) { throw new IOException("End of stream reached and still no <ETX> byte"); } // Parse contents of "temp" (it contains the entire CIMD message // including STX and ETX bytes). byte bytes[] = temp.toByteArray(); if (logger.isTraceEnabled()) { logger.trace("Received " + bytes.length + " byte(s)"); } if (useChecksum) { // Read two (2) bytes, just before the ETX byte. StringBuilder buffer = new StringBuilder(2); buffer.append((char) bytes[bytes.length - 3]); buffer.append((char) bytes[bytes.length - 2]); try { int checksum = Integer.valueOf(buffer.toString(), 16); int expectedChecksum = calculateCheckSum(bytes, 0, bytes.length - 3); if (checksum != expectedChecksum) { throw new IOException("Checksum error: expecting " + expectedChecksum + " but got " + checksum); } } catch (NumberFormatException e) { throw new IOException("Checksum error: expecting HEX digits, but got " + buffer); } } // Deserialize bytes, minus STX, CC (check sum), and ETX. int end = useChecksum ? bytes.length - 3 : bytes.length - 1; Packet packet = deserializeFromByteArray(bytes, 1, end); if (logger.isDebugEnabled()) { logger.debug("Received " + packet); } return packet; }
From source file:cn.scala.es.HeartBeat.java
HeartBeat(final Progressable progressable, Configuration cfg, TimeValue lead, final Log log) { Assert.notNull(progressable, "a valid progressable is required to report status to Hadoop"); TimeValue tv = HadoopCfgUtils.getTaskTimeout(cfg); Assert.isTrue(tv.getSeconds() <= 0 || tv.getSeconds() > lead.getSeconds(), "Hadoop timeout is shorter than the heartbeat"); this.progressable = progressable; long cfgMillis = (tv.getMillis() > 0 ? tv.getMillis() : 0); // the task is simple hence the delay = timeout - lead, that is when to start the notification right before the timeout this.delay = new TimeValue(Math.abs(cfgMillis - lead.getMillis()), TimeUnit.MILLISECONDS); this.log = log; String taskId;// w ww . j ava2 s . c om TaskID taskID = HadoopCfgUtils.getTaskID(cfg); if (taskID == null) { log.warn("Cannot determine task id..."); taskId = "<unknown>"; if (log.isTraceEnabled()) { log.trace("Current configuration is " + HadoopCfgUtils.asProperties(cfg)); } } else { taskId = "" + taskID; } id = taskId; }
From source file:com.microsoft.tfs.client.common.framework.command.TeamExplorerLogCommandFinishedCallback.java
@Override public void onCommandFinished(final ICommand command, IStatus status) { /*/*from w ww . j a v a 2s .c om*/ * Team Explorer ("private") logging. Map IStatus severity to commons * logging severity iff the severity is greater than the configured * tfsLogMinimumSeverity. */ if (status.getSeverity() >= minimumSeverity) { /* * UncaughtCommandExceptionStatus is a TeamExplorerStatus, which * does a silly trick: it makes the exception it was given * accessible only through a non-standard method. This helps when * displaying the status to the user in a dialog, but prevents the * platform logger from logging stack traces, so fix it up here. * * The right long term fix is to ditch TeamExplorerStatus entirely. */ if (status instanceof TeamExplorerStatus) { status = ((TeamExplorerStatus) status).toNormalStatus(); } /* * Don't have a static Log for this class, because then the errors * show up as coming from this class, which is not correct. Instead, * get the logger for the class the errors originated from. Note * that this is not a particularly expensive operation - it looks up * the classname in a hashmap. This should be more than suitable for * a command finished error handler. */ final Log log = LogFactory.getLog(CommandHelpers.unwrapCommand(command).getClass()); if (status.getSeverity() == IStatus.ERROR && log.isErrorEnabled()) { log.error(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (status.getSeverity() == IStatus.WARNING && log.isWarnEnabled()) { log.error(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (status.getSeverity() == IStatus.INFO && log.isInfoEnabled()) { log.info(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (status.getSeverity() == IStatus.CANCEL && log.isInfoEnabled()) { log.info(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (status.getSeverity() != IStatus.OK && log.isDebugEnabled()) { log.debug(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (log.isTraceEnabled()) { log.trace(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } } }
From source file:name.livitski.tools.springlet.Launcher.java
/** * Configures the manager using command-line arguments. * The arguments are checked in their command line sequence. * If an argument begins with {@link Command#COMMAND_PREFIX}, * its part that follows it is treated as a (long) command's name. * If an argument begins with {@link Command#SWITCH_PREFIX}, * the following character(s) are treated as a switch. * The name or switch extracted this way, prepended with * a bean name prefix for a {@link #BEAN_NAME_PREFIX_COMMAND command} * or a {@link #BEAN_NAME_PREFIX_SWITCH switch}, becomes the name * of a bean to look up in the framework's * {@link #MAIN_BEAN_CONFIG_FILE configuration file(s)}. * The bean that handles a command must extend the * {@link Command} class. Once a suitable bean is found, * it is called to act upon the command or switch and process * any additional arguments associated with it. * If no bean can be found or the argument is not prefixed * properly, it is considered unclaimed. You may configure a * special subclass of {@link Command} to process such arguments * by placing a bean named {@link #BEAN_NAME_DEFAULT_HANDLER} on * the configuration. If there is no such bean configured, or when * any {@link Command} bean throws an exception while processing * a command, a command line error is reported and the application * quits.//ww w.ja v a2 s.c o m * @param args the command line * @return this manager object */ public Launcher withArguments(String[] args) { configureDefaultLogging(); final Log log = log(); ListIterator<String> iargs = Arrays.asList(args).listIterator(); while (iargs.hasNext()) { String arg = iargs.next(); String prefix = null; String beanPrefix = null; Command cmd = null; if (arg.startsWith(Command.COMMAND_PREFIX)) prefix = Command.COMMAND_PREFIX; else if (arg.startsWith(Command.SWITCH_PREFIX)) prefix = Command.SWITCH_PREFIX; if (null != prefix) { arg = arg.substring(prefix.length()); beanPrefix = Command.SWITCH_PREFIX == prefix ? BEAN_NAME_PREFIX_SWITCH : BEAN_NAME_PREFIX_COMMAND; try { cmd = getBeanFactory().getBean(beanPrefix + arg, Command.class); } catch (NoSuchBeanDefinitionException noBean) { log.debug("Could not find a handler for command-line argument " + prefix + arg, noBean); } } if (null == cmd) { iargs.previous(); try { cmd = getBeanFactory().getBean(BEAN_NAME_DEFAULT_HANDLER, Command.class); } catch (RuntimeException ex) { log.error("Unknown command line argument: " + (null != prefix ? prefix : "") + arg, ex); status = STATUS_COMMAND_PARSING_FAILURE; break; } } try { cmd.process(iargs); } catch (SkipApplicationRunRequest skip) { if (log.isTraceEnabled()) log.trace("Handler for argument " + (null != prefix ? prefix : "") + arg + " requested to skip the application run", skip); status = STATUS_RUN_SKIPPED; break; } catch (RuntimeException err) { log.error("Invalid command line argument(s) near " + (null != prefix ? prefix : "") + arg + ": " + err.getMessage(), err); status = STATUS_COMMAND_PARSING_FAILURE; break; } catch (ApplicationBeanException err) { log.error("Error processing command line argument " + (null != prefix ? prefix : "") + arg + ": " + err.getMessage(), err); try { err.updateBeanStatus(); } catch (RuntimeException noStatus) { final ApplicationBean appBean = err.getApplicationBean(); log.warn("Could not obtain status code" + (null != appBean ? " from " + appBean : ""), noStatus); status = STATUS_INTERNAL_ERROR; } break; } } return this; }
From source file:org.alfresco.extension.bulkimport.util.LogUtils.java
public final static boolean trace(final Log log) { return (log.isTraceEnabled()); }