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);

Source Link

Document

Logs a message with error log level.

Usage

From source file:org.apache.myfaces.util.DebugUtils.java

public static void assertError(boolean condition, Log log_, String msg) throws FacesException {
    if (!condition) {
        log_.error(msg);
        throw new FacesException(msg);
    }// ww  w.j av a2  s .  c o m
}

From source file:org.apache.pig.impl.plan.CompilationMessageCollector.java

private static void logMessage(String messageString, MessageType messageType, Log log) {
    switch (messageType) {
    case Info:/*w ww  .  ja va2 s . com*/
        log.info(messageString);
        break;
    case Warning:
        log.warn(messageString);
        break;
    case Error:
        log.error(messageString);
    }
}

From source file:org.apache.pig.impl.util.LogUtils.java

public static void writeLog(Throwable t, String logFileName, Log log, boolean verbose, String headerMessage,
        boolean displayFooter, boolean displayMessage) {

    String message = null;/*from  w  w  w . ja  va 2s . c  om*/
    String marker = null;
    StringBuilder sb = new StringBuilder("=");

    for (int i = 0; i < 79; ++i) {
        sb.append("=");
    }
    sb.append("\n");
    marker = sb.toString();

    if (t instanceof Exception) {
        Exception pe = LogUtils.getPermissionException((Exception) t);
        if (pe != null) {
            log.error("You don't have permission to perform the operation. Error from the server: "
                    + pe.getMessage());
        }
    }

    PigException pigException = LogUtils.getPigException(t);

    if (pigException != null) {
        message = "ERROR " + pigException.getErrorCode() + ": " + pigException.getMessage();
    } else {
        if ((t instanceof ParseException || t instanceof org.apache.pig.tools.pigscript.parser.TokenMgrError
                || t instanceof org.apache.pig.tools.parameters.TokenMgrError)) {
            message = "ERROR 1000: Error during parsing. " + t.getMessage();
        } else if (t instanceof IOException) {
            message = "ERROR 2997: Encountered IOException. " + t.getMessage();
        } else if (t instanceof RuntimeException) {
            message = "ERROR 2999: Unexpected internal error. " + t.getMessage();
        } else {
            message = "ERROR 2998: Unhandled internal error. " + t.getMessage();
        }
    }

    FileOutputStream fos = null;
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    t.printStackTrace(new PrintStream(bs));

    if (displayMessage)
        log.error(message);

    if (verbose) {
        log.error(bs.toString());
    }

    if (logFileName == null || logFileName.equals("")) {
        //if exec is invoked programmatically then logFileName will be null
        log.warn("There is no log file to write to.");
        log.error(bs.toString());
        return;
    }

    File logFile = new File(logFileName);
    try {
        fos = new FileOutputStream(logFile, true);
        if (headerMessage != null) {
            fos.write((headerMessage + "\n").getBytes("UTF-8"));
            sb = new StringBuilder("-");
            for (int i = 1; i < headerMessage.length(); ++i) {
                sb.append("-");
            }
            sb.append("\n");
            fos.write(sb.toString().getBytes("UTF-8"));
        }
        if (message != null) {
            if (message.charAt(message.length() - 1) == '\n') {
                fos.write((message + "\n").getBytes("UTF-8"));
            } else {
                fos.write((message + "\n\n").getBytes("UTF-8"));
            }
        }
        fos.write(bs.toString().getBytes("UTF-8"));
        fos.write(marker.getBytes("UTF-8"));
        if (displayFooter) {
            if (verbose) {
                System.err.println("Details also at logfile: " + logFileName);
            } else {
                System.err.println("Details at logfile: " + logFileName);
            }
        }
    } catch (IOException ioe) {
        log.warn("Could not write to log file: " + logFileName + " :" + ioe.getMessage());
        log.error(bs.toString());
    } finally {
        try {
            if (fos != null)
                fos.close();
        } catch (IOException e) {
        }
    }
}

From source file:org.apache.pig.impl.util.LogUtils.java

public static void writeLog(String headerMessage, String message, String logFileName, Log log) {
    if (logFileName == null || logFileName.equals("")) {
        //if exec is invoked programmatically then logFileName will be null
        log.warn("There is no log file to write to.");
        log.error(headerMessage + "\n" + message);
        return;/*from   w  w w.ja v  a 2  s.  c om*/
    }

    File logFile = new File(logFileName);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(logFile, true);
        if (headerMessage != null) {
            fos.write((headerMessage + "\n").getBytes("UTF-8"));
            StringBuilder sb = new StringBuilder("-");
            for (int i = 1; i < headerMessage.length(); ++i) {
                sb.append("-");
            }
            sb.append("\n");
            fos.write(sb.toString().getBytes("UTF-8"));
        }
        if (message != null) {
            if (message.charAt(message.length() - 1) == '\n') {
                fos.write((message + "\n").getBytes("UTF-8"));
            } else {
                fos.write((message + "\n\n").getBytes("UTF-8"));
            }
        }
    } catch (IOException ioe) {
        log.warn("Could not write to log file: " + logFileName + " :" + ioe.getMessage());
        log.error(message);
    } finally {
        try {
            fos.close();
        } catch (IOException e) {
        }
    }
}

From source file:org.apache.ranger.audit.provider.MiscUtil.java

/**
 * @param string/*from   ww w  .j  a v a 2s. c o  m*/
 * @param e
 */
static public boolean logErrorMessageByInterval(Log useLogger, String message, Throwable e) {
    if (message == null) {
        return false;
    }

    LogHistory log = logHistoryList.get(message);
    if (log == null) {
        log = new LogHistory();
        logHistoryList.put(message, log);
    }
    if ((System.currentTimeMillis() - log.lastLogTime) > logInterval) {
        log.lastLogTime = System.currentTimeMillis();
        int counter = log.counter;
        log.counter = 0;
        if (counter > 0) {
            message += ". Messages suppressed before: " + counter;
        }
        if (e == null) {
            useLogger.error(message);
        } else {
            useLogger.error(message, e);
        }

        return true;
    } else {
        log.counter++;
    }
    return false;

}

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

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

From source file:org.apache.synapse.config.xml.OMElementUtils.java

/**
 * Add the namespace declarations of a given {@link OMElement} to the namespace
 * context of an XPath expression. Typically this method is used with an XPath
 * expression appearing in an attribute of the given element.
 * <p>//from   ww  w  . j  av a2  s  .  c  o m
 * Note that the default namespace is explicitly excluded and not added to the
 * namespace context. This implies that XPath expressions
 * appearing in Synapse configuration files follow the same rule as in XSL
 * stylesheets. Indeed, the XSLT specification defines the namespace context of
 * an XPath expression as follows:
 * <blockquote>
 * the set of namespace declarations are those in scope on the element which has the
 * attribute in which the expression occurs; [...] the default namespace
 * (as declared by xmlns) is not part of this set
 * </blockquote>
 * 
 * @param xpath
 * @param elem
 * @param log
 */
public static void addNameSpaces(XPath xpath, OMElement elem, Log log) {

    OMElement currentElem = elem;

    while (currentElem != null) {
        Iterator it = currentElem.getAllDeclaredNamespaces();
        while (it.hasNext()) {

            OMNamespace n = (OMNamespace) it.next();
            // Exclude the default namespace as explained in the Javadoc above
            if (n != null && !"".equals(n.getPrefix())) {

                try {
                    xpath.addNamespace(n.getPrefix(), n.getNamespaceURI());
                } catch (JaxenException je) {
                    String msg = "Error adding declared name space with prefix : " + n.getPrefix()
                            + "and uri : " + n.getNamespaceURI() + " to the XPath : " + xpath;
                    log.error(msg);
                    throw new SynapseException(msg, je);
                }
            }
        }

        OMContainer parent = currentElem.getParent();
        //if the parent is a document element or parent is null ,then return
        if (parent == null || parent instanceof OMDocument) {
            return;
        }
        if (parent instanceof OMElement) {
            currentElem = (OMElement) parent;
        }
    }
}

From source file:org.apache.synapse.handler.util.HandlerUtil.java

public static boolean mediateInMessage(Log log, MessageContext messageContext,
        org.apache.synapse.MessageContext synCtx) throws AxisFault {

    AxisService service = messageContext.getAxisService();
    if (service != null) {
        Parameter inMediationParam = service.getParameter(HandlerConstants.IN_SEQUENCE_PARAM_NAME);
        if (inMediationParam != null && inMediationParam.getValue() != null) {
            if (inMediationParam.getValue() instanceof Mediator) {
                Mediator inMessageSequence = (Mediator) inMediationParam.getValue();
                return inMessageSequence.mediate(synCtx);
            } else if (inMediationParam.getValue() instanceof String) {
                Mediator inMessageSequence = synCtx.getConfiguration()
                        .getSequence((String) inMediationParam.getValue());
                return inMessageSequence.mediate(synCtx);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("The provided in message mediation " + "sequence is not a proper mediator");
                }//from   w w w. j av  a 2  s.  c  o m
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Couldn't find the incoming mediation for the service " + service.getName());
            }
        }
    } else {
        String message = "Couldn't find the Service for the associated message with id "
                + messageContext.getMessageID();
        log.error(message);
        throw new AxisFault(message);
    }
    return true;
}

From source file:org.apache.synapse.handler.util.HandlerUtil.java

public static boolean mediateOutMessage(Log log, MessageContext messageContext,
        org.apache.synapse.MessageContext synCtx) throws AxisFault {

    AxisService service = messageContext.getAxisService();
    if (service != null) {
        Parameter inMediationParam = service.getParameter(HandlerConstants.OUT_SEQUENCE_PARAM_NAME);
        if (inMediationParam != null && inMediationParam.getValue() != null) {
            if (inMediationParam.getValue() instanceof Mediator) {
                Mediator inMessageSequence = (Mediator) inMediationParam.getValue();
                return inMessageSequence.mediate(synCtx);
            } else if (inMediationParam.getValue() instanceof String) {
                Mediator inMessageSequence = synCtx.getConfiguration()
                        .getSequence((String) inMediationParam.getValue());
                return inMessageSequence.mediate(synCtx);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("The provided out message mediation " + "sequence is not a proper mediator");
                }/* ww  w .  ja va 2s .co  m*/
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Couldn't find the outgoing mediation for the service " + service.getName());
            }
        }
    } else {
        String message = "Couldn't find the Service for the associated message with id "
                + messageContext.getMessageID();
        log.error(message);
        throw new AxisFault(message);
    }
    return true;
}

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

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