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

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

Introduction

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

Prototype

void info(Object message, Throwable t);

Source Link

Document

Logs an error with info log level.

Usage

From source file:org.latticesoft.util.common.LogUtil.java

public static void log(int level, Object o, Throwable t, Log log) {
    if (level == LogUtil.DEBUG)
        log.debug(o, t);//from   w ww  .  j  a  v  a 2 s .co m
    else if (level == LogUtil.ERROR)
        log.error(o, t);
    else if (level == LogUtil.FATAL)
        log.fatal(o, t);
    else if (level == LogUtil.INFO)
        log.info(o, t);
    else if (level == LogUtil.TRACE)
        log.trace(o, t);
    else if (level == LogUtil.WARNING)
        log.warn(o, t);
}

From source file:org.sakaiproject.site.tool.SiteAction.java

/**
 * Handle File Upload request//from w w  w .j a  v  a  2 s  .  c  o m
 * 
 * @see case 46
 * @throws Exception
 */
public void doUpload_Mtrl_Frm_File(RunData data) {
    SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    List allzipList = new Vector();
    List finalzipList = new Vector();
    List directcopyList = new Vector();

    // see if the user uploaded a file
    FileItem fileFromUpload = null;
    String fileName = null;
    fileFromUpload = data.getParameters().getFileItem("file");

    String max_file_size_mb = ServerConfigurationService.getString("content.upload.max", "1");
    long max_bytes = 1024 * 1024;
    try {
        max_bytes = Long.parseLong(max_file_size_mb) * 1024 * 1024;
    } catch (Exception e) {
        // if unable to parse an integer from the value
        // in the properties file, use 1 MB as a default
        max_file_size_mb = "1";
        max_bytes = 1024 * 1024;
        M_log.error(this + ".doUpload_Mtrl_Frm_File: wrong setting of content.upload.max = " + max_file_size_mb,
                e);
    }
    if (fileFromUpload == null) {
        // "The user submitted a file to upload but it was too big!"
        addAlert(state, rb.getFormattedMessage("importFile.size", new Object[] { max_file_size_mb }));
    } else if (fileFromUpload.getFileName() == null || fileFromUpload.getFileName().length() == 0) {
        addAlert(state, rb.getString("importFile.choosefile"));
    } else {
        //Need some other kind of input stream?
        ResetOnCloseInputStream fileInput = null;
        InputStream fileInputStream = null;
        long fileSize = 0;
        try {
            // Write to temp file, this should probably be in the velocity util?
            File tempFile = null;
            tempFile = File.createTempFile("importFile", ".tmp");
            // Delete temp file when program exits.
            tempFile.deleteOnExit();

            fileInputStream = fileFromUpload.getInputStream();

            FileOutputStream outBuf = new FileOutputStream(tempFile);
            byte[] bytes = new byte[102400];
            int read = 0;
            while ((read = fileInputStream.read(bytes)) != -1) {
                outBuf.write(bytes, 0, read);
            }

            outBuf.flush();
            outBuf.close();

            fileSize = tempFile.length();
            fileInput = new ResetOnCloseInputStream(tempFile);
        } catch (FileNotFoundException fnfe) {
            M_log.error("FileNotFoundException creating temp import file", fnfe);
        } catch (IOException ioe) {
            M_log.error("IOException creating temp import file", ioe);
        } finally {
            IOUtils.closeQuietly(fileInputStream);
        }

        if (fileSize >= max_bytes) {
            addAlert(state, rb.getFormattedMessage("importFile.size", new Object[] { max_file_size_mb }));
        } else if (fileSize > 0) {

            if (fileInput != null && importService.isValidArchive(fileInput)) {
                ImportDataSource importDataSource = importService.parseFromFile(fileInput);
                Log.info("chef", "Getting import items from manifest.");
                List lst = importDataSource.getItemCategories();
                if (lst != null && lst.size() > 0) {
                    Iterator iter = lst.iterator();
                    while (iter.hasNext()) {
                        ImportMetadata importdata = (ImportMetadata) iter.next();
                        // Log.info("chef","Preparing import
                        // item '" + importdata.getId() + "'");
                        if ((!importdata.isMandatory()) && (importdata.getFileName().endsWith(".xml"))) {
                            allzipList.add(importdata);
                        } else {
                            directcopyList.add(importdata);
                        }
                    }
                }
                // set Attributes
                state.setAttribute(ALL_ZIP_IMPORT_SITES, allzipList);
                state.setAttribute(FINAL_ZIP_IMPORT_SITES, finalzipList);
                state.setAttribute(DIRECT_ZIP_IMPORT_SITES, directcopyList);
                state.setAttribute(CLASSIC_ZIP_FILE_NAME, fileName);
                state.setAttribute(IMPORT_DATA_SOURCE, importDataSource);

                state.setAttribute(STATE_TEMPLATE_INDEX, "46");
            } else { // uploaded file is not a valid archive
                addAlert(state, rb.getString("importFile.invalidfile"));
            }
        }

        IOUtils.closeQuietly(fileInput);
    }
}

From source file:org.sakaiproject.site.tool.SiteAction.java

/**
 * Handle the request for Save// ww  w  . j a va2 s .  c  o  m
 * 
 * @param data
 * @throws ImportException
 */
public void doSaveMtrlSite(RunData data) {
    SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    String siteId = (String) state.getAttribute(STATE_SITE_INSTANCE_ID);
    List fnlList = (List) state.getAttribute(FINAL_ZIP_IMPORT_SITES);
    List directList = (List) state.getAttribute(DIRECT_ZIP_IMPORT_SITES);
    ImportDataSource importDataSource = (ImportDataSource) state.getAttribute(IMPORT_DATA_SOURCE);

    // combine the selected import items with the mandatory import items
    fnlList.addAll(directList);
    Log.info("chef", "doSaveMtrlSite() about to import " + fnlList.size() + " top level items");
    Log.info("chef", "doSaveMtrlSite() the importDataSource is " + importDataSource.getClass().getName());
    if (importDataSource instanceof SakaiArchive) {
        Log.info("chef", "doSaveMtrlSite() our data source is a Sakai format");
        ((SakaiArchive) importDataSource).buildSourceFolder(fnlList);
        Log.info("chef",
                "doSaveMtrlSite() source folder is " + ((SakaiArchive) importDataSource).getSourceFolder());
        ArchiveService.merge(((SakaiArchive) importDataSource).getSourceFolder(), siteId, null);
    } else {
        importService.doImportItems(importDataSource.getItemsForCategories(fnlList), siteId);
    }
    // remove attributes
    state.removeAttribute(ALL_ZIP_IMPORT_SITES);
    state.removeAttribute(DIRECT_ZIP_IMPORT_SITES);
    state.removeAttribute(CLASSIC_ZIP_FILE_NAME);
    state.removeAttribute(SESSION_CONTEXT_ID);
    state.removeAttribute(IMPORT_DATA_SOURCE);

    state.setAttribute(STATE_TEMPLATE_INDEX, "48");

}

From source file:org.springframework.flex.core.CommonsLoggingTarget.java

public void logEvent(LogEvent logevent) {
    String category = logevent.logger.getCategory();
    if (this.categoryPrefix != null) {
        category = this.categoryPrefix + "." + category;
    }/*  www  . j  a  va 2 s  .  c o m*/
    Log log = LogFactory.getLog(category);
    switch (logevent.level) {
    case LogEvent.FATAL:
        if (log.isFatalEnabled()) {
            log.fatal(logevent.message, logevent.throwable);
        }
        break;
    case LogEvent.ERROR:
        if (log.isErrorEnabled()) {
            log.error(logevent.message, logevent.throwable);
        }
        break;
    case LogEvent.WARN:
        if (log.isWarnEnabled()) {
            log.warn(logevent.message, logevent.throwable);
        }
        break;
    case LogEvent.INFO:
        if (log.isInfoEnabled()) {
            log.info(logevent.message, logevent.throwable);
        }
        break;
    case LogEvent.DEBUG:
        if (log.isDebugEnabled()) {
            log.debug(logevent.message, logevent.throwable);
        }
        break;
    case LogEvent.ALL:
        if (log.isTraceEnabled()) {
            log.trace(logevent.message, logevent.throwable);
        }
        break;
    default:
        break;
    }
}

From source file:org.springframework.orm.toplink.support.CommonsLoggingSessionLog.java

public void log(SessionLogEntry entry) {
    Log logger = LogFactory.getLog(getCategory(entry));
    switch (entry.getLevel()) {
    case SEVERE://from   w  w  w.j  a v a 2 s  .c o  m
        if (logger.isErrorEnabled()) {
            if (entry.hasException()) {
                logger.error(getMessageString(entry), getException(entry));
            } else {
                logger.error(getMessageString(entry));
            }
        }
        break;
    case WARNING:
        if (logger.isWarnEnabled()) {
            if (entry.hasException()) {
                logger.warn(getMessageString(entry), getException(entry));
            } else {
                logger.warn(getMessageString(entry));
            }
        }
        break;
    case INFO:
        if (logger.isInfoEnabled()) {
            if (entry.hasException()) {
                logger.info(getMessageString(entry), getException(entry));
            } else {
                logger.info(getMessageString(entry));
            }
        }
        break;
    case CONFIG:
    case FINE:
    case FINER:
        if (logger.isDebugEnabled()) {
            if (entry.hasException()) {
                logger.debug(getMessageString(entry), getException(entry));
            } else {
                logger.debug(getMessageString(entry));
            }
        }
        break;
    case FINEST:
        if (logger.isTraceEnabled()) {
            if (entry.hasException()) {
                logger.trace(getMessageString(entry), getException(entry));
            } else {
                logger.trace(getMessageString(entry));
            }
        }
        break;
    }
}

From source file:org.swordess.ldap.util.LogUtils.java

public static void info(Log log, Object message, Throwable t) {
    if (log.isInfoEnabled()) {
        log.info(message, t);
    }/*from  w w w . j  av  a 2 s.  c o m*/
}

From source file:org.xflatdb.xflat.db.TableMetadataFactory.java

/**
 * Gets the metadata document for the given table name.
 * @param name The table name for which to get the metadata document.
 * @return A Document representing the metadata associated to the table.
 *///from   w w  w.  j a v  a2 s.  c  o  m
public Document getMetadataDoc(String name) {
    try {
        return this.wrapper.readFile(name + ".config.xml");
    } catch (IOException | JDOMException ex) {
        Log log = LogFactory.getLog(getClass());
        if (log.isInfoEnabled())
            log.info(String.format("corrupt metadata file: %s.config.xml in directory %s", name,
                    this.wrapper.toString()), ex);

        return null;
    }
}

From source file:org.xflatdb.xflat.db.TableMetadataFactory.java

/**
 * Creates a TableMetadata for the given engine.  This TableMetadata object
 * does not have the ID generator or table config, so it can function only as
 * an EngineProvider.  Do not call {@link TableMetadata#getTable(java.lang.Class) } on the
 * resulting object./*from w w  w .java  2 s . c  o  m*/
 * @param name The name of the table.
 * @param engineFile The file where the engine data should be stored.
 * @return A new TableMetadata object.
 */
public TableMetadata makeTableMetadata(String name, File engineFile) {
    Document doc;

    try {
        doc = this.wrapper.readFile(name + ".config.xml");
    } catch (IOException | JDOMException ex) {
        Log log = LogFactory.getLog(getClass());
        if (log.isInfoEnabled())
            log.info(String.format("corrupt metadata file: %s.config.xml in directory %s", name,
                    this.wrapper.toString()), ex);

        doc = null;
    }

    TableMetadata ret = new TableMetadata(name, db, engineFile);

    if (doc == null) {
        //no need for config or ID generator
        ret.engineMetadata = new Element("engine", XFlatConstants.xFlatNs);
    } else {
        //load engine
        ret.engineMetadata = doc.getRootElement().getChild("engine", XFlatConstants.xFlatNs);
        if (ret.engineMetadata == null) {
            ret.engineMetadata = new Element("engine", XFlatConstants.xFlatNs);
        }
    }

    return ret;
}

From source file:org.xflatdb.xflat.db.TableMetadataFactory.java

/**
 * Creates a TableMetadata for the given table information.
 * @param name The name of the table/*  w ww.ja va2  s. c  om*/
 * @param engineFile The file locating the engine.
 * @param config The configuration of the table, null to use {@link TableConfig#DEFAULT}
 * @param idType The type of the ID property for the table.
 * @return A table metadata for the given table.
 */
public TableMetadata makeTableMetadata(String name, File engineFile, TableConfig config, Class<?> idType) {
    Document doc;
    TableMetadata ret;
    try {
        doc = this.wrapper.readFile(name + ".config.xml");
    } catch (IOException | JDOMException ex) {
        Log log = LogFactory.getLog(getClass());
        if (log.isInfoEnabled())
            log.info(String.format("regenerating corrupt metadata file: %s.config.xml in directory %s", name,
                    this.wrapper.toString()), ex);

        doc = null;
    }

    if (doc == null) {
        ret = makeNewTableMetadata(name, engineFile, config, idType);
    } else {
        ret = makeTableMetadataFromDocument(name, engineFile, doc, config, idType);
    }

    return ret;
}