Example usage for org.apache.commons.logging Log trace

List of usage examples for org.apache.commons.logging Log trace

Introduction

In this page you can find the example usage for org.apache.commons.logging Log trace.

Prototype

void trace(Object message, Throwable t);

Source Link

Document

Logs an error with trace log level.

Usage

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.
 * /*w w w .j a v  a2  s.  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);
                        }//  w w  w .j  a v  a 2s.  c  om
                    }
                } 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:ductive.log.JDKToCommonsHandler.java

@Override
public void publish(LogRecord record) {
    String name = record.getLoggerName();

    Log log = logs.get(name);
    if (log == null)
        logs.put(name, log = LogFactory.getLog(name));

    String message = record.getMessage();
    Throwable ex = record.getThrown();
    Level level = record.getLevel();

    if (Level.SEVERE == level)
        log.error(message, ex);//w  w  w.jav  a 2  s .  co  m
    else if (Level.WARNING == level)
        log.warn(message, ex);
    else if (Level.INFO == level)
        log.info(message, ex);
    else if (Level.CONFIG == level)
        log.debug(message, ex);
    else
        log.trace(message, ex);
}

From source file:com.microsoft.tfs.client.common.framework.command.TeamExplorerLogCommandFinishedCallback.java

@Override
public void onCommandFinished(final ICommand command, IStatus status) {
    /*//  w w  w.j  a va2 s  .co  m
     * 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:com.ayovel.nian.exception.XLog.java

private void log(Level level, int loggerMask, String msgTemplate, Object... params) {
    loggerMask |= STD;/*  ww  w  .j  a v a 2s .  c o  m*/
    if (isEnabled(level, loggerMask)) {
        String prefix = getMsgPrefix() != null ? getMsgPrefix() : Info.get().getPrefix();
        prefix = (prefix != null && prefix.length() > 0) ? prefix + " " : "";

        String msg = prefix + format(msgTemplate, params);
        Throwable throwable = getCause(params);

        for (int i = 0; i < LOGGER_MASKS.length; i++) {
            if (isEnabled(level, loggerMask & LOGGER_MASKS[i])) {
                Log log = loggers[i];
                switch (level) {
                case FATAL:
                    log.fatal(msg, throwable);
                    break;
                case ERROR:
                    log.error(msg, throwable);
                    break;
                case INFO:
                    log.info(msg, throwable);
                    break;
                case WARN:
                    log.warn(msg, throwable);
                    break;
                case DEBUG:
                    log.debug(msg, throwable);
                    break;
                case TRACE:
                    log.trace(msg, throwable);
                    break;
                }
            }
        }
    }
}

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./*  w  ww  .  jav  a2s . co 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 void trace(final Log log, final String message, final Throwable cause) {
    log.trace(PREFIX + message, cause);
}

From source file:org.alfresco.extension.bulkimport.util.LogUtils.java

public final static void trace(final Log log, final Throwable cause) {
    log.trace(RAW_EXCEPTION, cause);
}

From source file:org.amplafi.flow.impl.FlowStateLoggerImpl.java

public void trace(Log logger, Object message, Throwable throwable) {
    if (logger == null) {
        logger = getLog();//from  www  . j a  va 2 s  . co m
    }
    StringBuilder stringBuilder = getFlowStatesString(message);
    logger.trace(stringBuilder, throwable);
}

From source file:org.easyrec.utils.spring.log.LoggerUtils.java

/**
 * Writes the given 'message' to the Log 'logger' with level 'logLevel'.
 *
 * @param logger   the Log to which the message is written
 * @param logLevel the level to which the message is written
 * @param message  the message to be written
 * @param ta       a Throwable passed on to the Log
 */// www .  ja  va2  s . c  om
public static void log(Log logger, String logLevel, String message, Throwable ta) {
    if (logLevel.equalsIgnoreCase("info")) {
        if (logger.isInfoEnabled()) {
            logger.info(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("debug")) {
        if (logger.isDebugEnabled()) {
            logger.debug(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("error")) {
        if (logger.isErrorEnabled()) {
            logger.error(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("trace")) {
        if (logger.isTraceEnabled()) {
            logger.trace(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("warn")) {
        if (logger.isWarnEnabled()) {
            logger.warn(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("fatal")) {
        if (logger.isFatalEnabled()) {
            logger.fatal(message, ta);
        }
    } else {
        logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!");
        logger.error(message, ta);
    }
}