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.fop.util.LogUtil.java

/**
 * Convenience method that handles any error appropriately
 * @param log log//from  ww w  . j  a va  2  s . com
 * @param e exception
 * @param strict validate strictly
 * @throws FOPException fop exception
 */
public static void handleException(Log log, Exception e, boolean strict) throws FOPException {
    if (strict) {
        if (e instanceof FOPException) {
            throw (FOPException) e;
        }
        throw new FOPException(e);
    }
    log.error(e.getMessage());
}

From source file:org.apache.fop.visual.ConvertUtils.java

/**
 * Calls an external converter application (GhostScript, for example).
 * @param cmd the full command/*from w  w  w . j  ava  2s  . c  om*/
 * @param envp array of strings, each element of which has environment variable settings
 * in format name=value.
 * @param workDir the working directory of the subprocess, or null if the subprocess should
 * inherit the working directory of the current process.
 * @param log the logger to log output by the external application to
 * @throws IOException in case the external call fails
 */
public static void convert(String cmd, String[] envp, File workDir, final Log log) throws IOException {
    log.debug(cmd);

    Process process = null;
    try {
        process = Runtime.getRuntime().exec(cmd, envp, null);

        //Redirect stderr output
        RedirectorLineHandler errorHandler = new AbstractRedirectorLineHandler() {
            public void handleLine(String line) {
                log.error("ERR> " + line);
            }
        };
        StreamRedirector errorRedirector = new StreamRedirector(process.getErrorStream(), errorHandler);

        //Redirect stdout output
        RedirectorLineHandler outputHandler = new AbstractRedirectorLineHandler() {
            public void handleLine(String line) {
                log.debug("OUT> " + line);
            }
        };
        StreamRedirector outputRedirector = new StreamRedirector(process.getInputStream(), outputHandler);
        new Thread(errorRedirector).start();
        new Thread(outputRedirector).start();

        process.waitFor();
    } catch (java.lang.InterruptedException ie) {
        throw new IOException("The call to the external converter failed: " + ie.getMessage());
    } catch (java.io.IOException ioe) {
        throw new IOException("The call to the external converter failed: " + ioe.getMessage());
    }

    int exitValue = process.exitValue();
    if (exitValue != 0) {
        throw new IOException("The call to the external converter failed. Result: " + exitValue);
    }

}

From source file:org.apache.hadoop.util.FlushableLogger.java

private FlushableLogger(Log log) {
    if (log == null) {
        String msg = "Log should not be null";
        LOG.error(msg);
        throw new IllegalArgumentException(msg);
    }//from  ww w.ja  v  a 2 s  . c  o m
    this.log = log;
}

From source file:org.apache.hupa.server.preferences.InImapUserPreferencesStorage.java

/**
 * Opens the IMAP folder, deletes all messages which match the magic subject and
 * creates a new message with an attachment which contains the object serialized
 *//*w w  w .j  a  va2s  . c  o  m*/
protected static void saveUserPreferencesInIMAP(Log logger, User user, Session session, IMAPStore iStore,
        String folderName, String subject, Object object)
        throws MessagingException, IOException, InterruptedException {
    IMAPFolder folder = (IMAPFolder) iStore.getFolder(folderName);

    if (folder.exists() || folder.create(IMAPFolder.HOLDS_MESSAGES)) {
        if (!folder.isOpen()) {
            folder.open(Folder.READ_WRITE);
        }

        // Serialize the object
        ByteArrayOutputStream fout = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(fout);
        oos.writeObject(object);
        oos.close();
        ByteArrayInputStream is = new ByteArrayInputStream(fout.toByteArray());

        // Create a new message with an attachment which has the serialized object
        MimeMessage message = new MimeMessage(session);
        message.setSubject(subject);

        Multipart multipart = new MimeMultipart();
        MimeBodyPart txtPart = new MimeBodyPart();
        txtPart.setContent("This message contains configuration used by Hupa, do not delete it", "text/plain");
        multipart.addBodyPart(txtPart);
        FileItem item = createPreferencesFileItem(is, subject, HUPA_DATA_MIME_TYPE);
        multipart.addBodyPart(MessageUtils.fileitemToBodypart(item));
        message.setContent(multipart);
        message.saveChanges();

        // It seems it's not possible to modify the content of an existing message using the API
        // So I delete the previous message storing the preferences and I create a new one
        Message[] msgs = folder.getMessages();
        for (Message msg : msgs) {
            if (subject.equals(msg.getSubject())) {
                msg.setFlag(Flag.DELETED, true);
            }
        }

        // It is necessary to copy the message before saving it (the same problem in AbstractSendMessageHandler)
        message = new MimeMessage((MimeMessage) message);
        message.setFlag(Flag.SEEN, true);
        folder.appendMessages(new Message[] { message });
        folder.close(true);
        logger.info("Saved preferences " + subject + " in imap folder " + folderName + " for user " + user);
    } else {
        logger.error("Unable to save preferences " + subject + " in imap folder " + folderName + " for user "
                + user);
    }
}

From source file:org.apache.hupa.server.utils.MessageUtils.java

/**
 * Extract the attachments present in a mime message
 *
 * @param logger/*from w w w .j  a  va2s.c  om*/
 * @param content
 * @return A list of body parts of the attachments
 * @throws MessagingException
 * @throws IOException
 */
static public List<BodyPart> extractMessageAttachments(Log logger, Object content)
        throws MessagingException, IOException {
    ArrayList<BodyPart> ret = new ArrayList<BodyPart>();
    if (content instanceof Multipart) {
        Multipart part = (Multipart) content;
        for (int i = 0; i < part.getCount(); i++) {
            BodyPart bodyPart = part.getBodyPart(i);
            String fileName = bodyPart.getFileName();
            String[] contentId = bodyPart.getHeader("Content-ID");
            if (bodyPart.isMimeType("multipart/*")) {
                ret.addAll(extractMessageAttachments(logger, bodyPart.getContent()));
            } else {
                if (contentId != null || fileName != null) {
                    ret.add(bodyPart);
                }
            }
        }
    } else {
        logger.error("Unknown content: " + content.getClass().getName());
    }
    return ret;
}

From source file:org.apache.hupa.server.utils.MessageUtils.java

/**
 * Loop over MuliPart and write the content to the Outputstream if a
 * attachment with the given name was found.
 *
 * @param logger//from ww  w. jav  a2 s  .  co  m
 *            The logger to use
 * @param content
 *            Content which should checked for attachments
 * @param attachmentName
 *            The attachmentname or the unique id for the searched attachment
 * @throws MessagingException
 * @throws IOException
 */
public static Part handleMultiPart(Log logger, Object content, String attachmentName)
        throws MessagingException, IOException {
    if (content instanceof Multipart) {
        Multipart part = (Multipart) content;
        for (int i = 0; i < part.getCount(); i++) {
            Part bodyPart = part.getBodyPart(i);
            String fileName = bodyPart.getFileName();
            String[] contentId = bodyPart.getHeader("Content-ID");
            if (bodyPart.isMimeType("multipart/*")) {
                Part p = handleMultiPart(logger, bodyPart.getContent(), attachmentName);
                if (p != null)
                    return p;
            } else {
                if (contentId != null) {
                    for (String id : contentId) {
                        id = id.replaceAll("^.*<(.+)>.*$", "$1");
                        System.out.println(attachmentName + " " + id);
                        if (attachmentName.equals(id))
                            return bodyPart;
                    }
                }
                if (fileName != null) {
                    if (cleanName(attachmentName).equalsIgnoreCase(cleanName(MimeUtility.decodeText(fileName))))
                        return bodyPart;
                }
            }
        }
    } else {
        logger.error("Unknown content: " + content.getClass().getName());
    }
    return null;
}

From source file:org.apache.logging.log4j.jcl.CallerInformationTest.java

@Test
public void testClassLogger() throws Exception {
    final ListAppender app = ctx.getListAppender("Class").clear();
    final Log logger = LogFactory.getLog("ClassLogger");
    logger.info("Ignored message contents.");
    logger.warn("Verifying the caller class is still correct.");
    logger.error("Hopefully nobody breaks me!");
    final List<String> messages = app.getMessages();
    assertEquals("Incorrect number of messages.", 3, messages.size());
    for (final String message : messages) {
        assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
    }// www  .j av a2 s .  c o m
}

From source file:org.apache.logging.log4j.jcl.CallerInformationTest.java

@Test
public void testMethodLogger() throws Exception {
    final ListAppender app = ctx.getListAppender("Method").clear();
    final Log logger = LogFactory.getLog("MethodLogger");
    logger.info("More messages.");
    logger.warn("CATASTROPHE INCOMING!");
    logger.error("ZOMBIES!!!");
    logger.warn("brains~~~");
    logger.info("Itchy. Tasty.");
    final List<String> messages = app.getMessages();
    assertEquals("Incorrect number of messages.", 5, messages.size());
    for (final String message : messages) {
        assertEquals("Incorrect caller method name.", "testMethodLogger", message);
    }/*from w  w  w  .  j a va2 s . c  o  m*/
}

From source file:org.apache.myfaces.custom.toggle.ToggleLinkRenderer.java

private String buildOnclickToggleFunction(FacesContext facesContext, UIOutput output) throws IOException {
    ToggleLink toggleLink = (ToggleLink) output;
    TogglePanel togglePanel = getParentTogglePanel(facesContext, toggleLink);
    String[] componentsToToggle = toggleLink.getFor().split(",");
    String idsToHide = getIdsToHide(facesContext, togglePanel);
    StringBuffer idsToShow = new StringBuffer();
    for (int i = 0; i < componentsToToggle.length; i++) {
        String componentId = componentsToToggle[i].trim();
        UIComponent componentToShow = toggleLink.findComponent(componentId);
        if (componentToShow == null) {
            Log log = LogFactory.getLog(ToggleLinkRenderer.class);
            log.error("Unable to find component with id " + componentId);
            continue;
        }/*from w w  w  . j a v a  2 s.  c  o  m*/
        if (idsToShow.length() > 0)
            idsToShow.append(',');
        idsToShow.append(componentToShow.getClientId(facesContext));
    }

    String outputOnclick = toggleLink.getOnclick();
    StringBuffer onClick = new StringBuffer();
    if (outputOnclick != null) {
        onClick.append("var cf = function(){");
        onClick.append(outputOnclick);
        onClick.append('}');
        onClick.append(';');
        onClick.append("var oamSF = function(){");
    }

    String onClickFocusClientId = toggleLink.getOnClickFocusId() != null
            ? toggleLink.findComponent(toggleLink.getOnClickFocusId()).getClientId(facesContext)
            : "";
    onClick.append(getToggleJavascriptFunctionName(facesContext, toggleLink) + "('" + idsToShow + "','"
            + idsToHide + "','" + getHiddenFieldId(facesContext, togglePanel) + "','" + onClickFocusClientId
            + "');");

    if (outputOnclick != null) {
        onClick.append('}');
        onClick.append(';');
        onClick.append("return (cf()==false)? false : oamSF();");
    }

    return onClick.toString();
}

From source file:org.apache.myfaces.custom.toggle.ToggleLinkRenderer.java

private String getToggleJavascriptFunctionName(FacesContext context, ToggleLink toggleLink) {
    for (UIComponent component = toggleLink.getParent(); component != null; component = component.getParent())
        if (component instanceof TogglePanel)
            return TogglePanelRenderer.getToggleJavascriptFunctionName(context, (TogglePanel) component);

    Log log = LogFactory.getLog(ToggleLinkRenderer.class);
    log.error("The ToggleLink component with id " + toggleLink.getClientId(context)
            + " isn't enclosed in a togglePanel.");
    return null;//from   w w  w.ja  va 2s  . c  o  m
}