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

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

Introduction

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

Prototype

void error(Object message, Throwable t);

Source Link

Document

Logs an error with error log level.

Usage

From source file:org.apache.myfaces.custom.graphicimagedynamic.util.GraphicsImageDynamicHelper.java

/**
 * This method is used for creating the image context.
 * @param facesContext//from   ww  w.java2  s . co  m
 * @return the imageContext.
 */
public static ImageContext createImageContext(FacesContext facesContext, Log log) {

    ExternalContext externalContext = facesContext.getExternalContext();
    final Map requestMap = externalContext.getRequestParameterMap();
    Object value = requestMap.get(GraphicImageDynamic.WIDTH_PARAM);
    Integer height = null;
    Integer width = null;

    if (value != null) {
        try {
            width = Integer.valueOf(value.toString());
        } catch (NumberFormatException e) {
            log.error("Invalid value for image width : " + value + ", " + e.getMessage(), e);
        }
    }

    value = requestMap.get(GraphicImageDynamic.HEIGHT_PARAM);
    if (value != null) {
        try {
            height = Integer.valueOf(value.toString());
        } catch (NumberFormatException e) {
            log.error("Invalid value for image height : " + value + ", " + e.getMessage(), e);
        }
    }

    return new SimpleImageContext(requestMap, width, height);
}

From source file:org.apache.sqoop.util.LoggingUtils.java

/**
 * Log every exception in the chain if//from w  w w . j ava2 s  .c  o  m
 * the exception is a chain of exceptions.
 */
public static void logAll(Log log, SQLException e) {
    log.error("Top level exception: ", e);
    e = e.getNextException();
    int indx = 1;
    while (e != null) {
        log.error("Chained exception " + indx + ": ", e);
        e = e.getNextException();
        indx++;
    }
}

From source file:org.apache.synapse.commons.SynapseCommonsException.java

public SynapseCommonsException(String msg, Throwable cause, Log synLog) {
    super(msg, cause);
    synLog.error(msg, cause);
}

From source file:org.apache.synapse.securevault.SecureVaultException.java

public SecureVaultException(String msg, Throwable cause, Log synLog) {
    super(msg, cause);
    synLog.error(msg, cause);
}

From source file:org.apache.synapse.task.SynapseTaskException.java

public SynapseTaskException(String msg, Throwable cause, Log log) {
    super(msg, cause);
    log.error(msg, cause);
}

From source file:org.apache.sysml.parser.AParserWrapper.java

public static String readDMLScript(String script, Log LOG) throws IOException, LanguageException {
    String dmlScriptStr = null;//w  w w  .j a va 2s.  com

    //read DML script from file
    if (script == null)
        throw new LanguageException("DML script path was not specified!");

    StringBuilder sb = new StringBuilder();
    BufferedReader in = null;
    try {
        //read from hdfs or gpfs file system
        if (script.startsWith("hdfs:") || script.startsWith("gpfs:")) {
            if (!LocalFileUtils.validateExternalFilename(script, true))
                throw new LanguageException("Invalid (non-trustworthy) hdfs filename.");
            FileSystem fs = FileSystem.get(ConfigurationManager.getCachedJobConf());
            Path scriptPath = new Path(script);
            in = new BufferedReader(new InputStreamReader(fs.open(scriptPath)));
        }
        // from local file system
        else {
            if (!LocalFileUtils.validateExternalFilename(script, false))
                throw new LanguageException("Invalid (non-trustworthy) local filename.");
            in = new BufferedReader(new FileReader(script));
        }

        //core script reading
        String tmp = null;
        while ((tmp = in.readLine()) != null) {
            sb.append(tmp);
            sb.append("\n");
        }
    } catch (IOException ex) {
        LOG.error("Failed to read the script from the file system", ex);
        throw ex;
    } finally {
        if (in != null)
            in.close();
    }

    dmlScriptStr = sb.toString();

    return dmlScriptStr;
}

From source file:org.apache.wsrp4j.commons.exception.WSRPXHelper.java

public static void throwX(Log extLog, int errorCode) throws WSRPException {

    WSRPException e = new WSRPException(errorCode);

    extLog.error(EMPTY_STRING, e);

    throw e;//  w  w  w .  j a  va  2 s  .  c om

}

From source file:org.atomserver.AtomServer.java

private void log500Error(Throwable e, Abdera abdera, RequestContext request) {
    if (errlog != null) {
        Log http500log = errlog.getLog();
        if (http500log.isInfoEnabled()) {
            try {
                http500log.info(//from   w  ww .j  a  va  2  s  .  c o m
                        "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
                http500log.info("==> 500 ERROR occurred for {" + request.getUri() + "} Type:: "
                        + e.getClass().getName() + " Reason:: " + e.getMessage());
                http500log.error("500 Error:: ", e);
                http500log.info("METHOD:: " + request.getMethod());
                if (request.getPrincipal() != null) {
                    http500log.info("PRINCIPAL:: " + request.getPrincipal().getName());
                }
                http500log.info("HEADERS:: ");
                String[] headerNames = request.getHeaderNames();
                if (headerNames != null) {
                    for (int ii = 0; ii < headerNames.length; ii++) {
                        http500log
                                .info("Header(" + headerNames[ii] + ")= " + request.getHeader(headerNames[ii]));
                    }
                }
                http500log.info("PARAMETERS:: ");
                String[] paramNames = request.getParameterNames();
                if (paramNames != null) {
                    for (int ii = 0; ii < paramNames.length; ii++) {
                        http500log.info(
                                "Parameter(" + paramNames[ii] + ")= " + request.getParameter(paramNames[ii]));
                    }
                }
                if (request instanceof HttpServletRequestContext) {
                    HttpServletRequestContext httpRequest = (HttpServletRequestContext) request;
                    javax.servlet.http.HttpServletRequest servletRequest = httpRequest.getRequest();
                    if (servletRequest != null) {
                        http500log.info("QUERY STRING::" + servletRequest.getQueryString());
                        http500log.info("AUTH TYPE:: " + servletRequest.getAuthType());
                        http500log.info("REMOTE USER:: " + servletRequest.getRemoteUser());
                        http500log.info("REMOTE ADDR:: " + servletRequest.getRemoteAddr());
                        http500log.info("REMOTE HOST:: " + servletRequest.getRemoteHost());
                    }
                }
                http500log.info("BODY:: ");
                if (request.getDocument() != null) {
                    java.io.StringWriter stringWriter = new java.io.StringWriter();
                    request.getDocument().writeTo(abdera.getWriterFactory().getWriter("PrettyXML"),
                            stringWriter);

                    //http500log.info( "\n" + stringWriter.toString() );
                    String requestString = stringWriter.toString();
                    if (requestString != null && requestString.length() > MAX_REQ_BODY_DUMP) {
                        requestString = requestString.substring(0, (MAX_REQ_BODY_DUMP - 1));
                    }

                    http500log.info("\n" + requestString);
                }
            } catch (Exception ee) {
            }
        }
    }
}

From source file:org.bibsonomy.util.ExceptionUtils.java

/**
 * Like the name suggests this method logs an error and throws a
 * RuntimeException attached with the initial exception.
 * @param log the logger instance to use
 * @param ex the exception to log an rethrow wrapped
 * @param error message of the new RuntimeException
 * @throws RuntimeException the resulting exception
 *///from w  ww .j  a v a  2s  . co  m
public static void logErrorAndThrowRuntimeException(final Log log, final Exception ex, final String error)
        throws RuntimeException {
    log.error(error + " - throwing RuntimeException" + ((ex != null) ? ("\n" + ex.toString()) : ""), ex);
    /*
     * Inserted to get more information (e.g., on "java.sql.SQLException: Unknown error" messages)
     * FIXME: it's probably not the best place to handle SQL stuff
     */
    if (ex != null && ex.getCause() != null && ex.getCause().getClass().equals(SQLException.class)) {
        final SQLException sqlException = ((SQLException) ex);
        log.error("SQL error code: " + sqlException.getErrorCode() + ", SQL state: "
                + sqlException.getSQLState());
    }
    throw new RuntimeException(error, ex);
}

From source file:org.codehaus.nanning.trace.TraceInterceptor.java

public Object invoke(Invocation invocation) throws Throwable {
    StopWatch watch = new StopWatch(false);

    Log logger = getLogger(invocation.getTarget().getClass());

    StringBuffer methodCallMessage = new StringBuffer();
    methodCallMessage.append(invocation.getMethod().getName());
    methodCallMessage.append('(');
    Object[] args = invocation.getArgs();
    if (args != null) {
        for (int i = 0; i < args.length; i++) {
            Object arg = args[i];
            methodCallMessage.append(arg);
            if (i + 1 < args.length) {
                methodCallMessage.append(", ");
            }/*from w ww  . j  av  a2s  .  c  o m*/
        }
    }
    methodCallMessage.append(')');
    logger.debug(">>> " + methodCallMessage);
    Object result = null;
    try {
        result = invocation.invokeNext();
        return result;
    } catch (Throwable e) {
        watch.stop();
        logger.error(
                "<<< " + methodCallMessage + " threw exception, took " + (int) watch.getTimeSpent() + " ms", e);
        throw e;
    } finally {
        watch.stop();
        logger.debug(
                "<<< " + methodCallMessage + ", took " + (int) watch.getTimeSpent() + " ms, result " + result);
    }
}