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

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

Introduction

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

Prototype

boolean isDebugEnabled();

Source Link

Document

Is debug logging currently enabled?

Usage

From source file:org.kuali.kra.logging.BufferedLogger.java

/**
 * Wraps {@link Log#debug(String)}/*  ww  w.ja  va  2s .co  m*/
 * 
 * @param pattern to format against
 * @param objs an array of objects used as parameters to the <code>pattern</code>
 */
public static final void debug(Object... objs) {
    Log log = getLogger();
    if (log.isDebugEnabled()) {
        log.debug(getMessage(objs));
    }
}

From source file:org.lilyproject.util.hbase.LocalHTable.java

public HTablePool getHTablePool(Configuration conf) {
    HTablePool pool;/*from   ww  w .  ja v  a2  s.  c  o  m*/
    synchronized (HTABLE_POOLS) {
        pool = HTABLE_POOLS.get(conf);
        if (pool == null) {
            pool = new HTablePool(conf, 20, new HTableFactory());
            HTABLE_POOLS.put(conf, pool);
            Log log = LogFactory.getLog(LocalHTable.class);
            if (log.isDebugEnabled()) {
                log.debug("Created a new HTablePool instance for conf " + System.identityHashCode(conf));
            }
        }
    }
    return pool;
}

From source file:org.mule.api.processor.LoggerMessageProcessorTestCase.java

private Log buildMockLogger() {
    Log mockLogger = mock(Log.class);
    doNothing().when(mockLogger).error(any());
    doNothing().when(mockLogger).warn(any());
    doNothing().when(mockLogger).info(any());
    doNothing().when(mockLogger).debug(any());
    doNothing().when(mockLogger).trace(any());

    // All levels enabled by default
    when(mockLogger.isErrorEnabled()).thenReturn(true);
    when(mockLogger.isWarnEnabled()).thenReturn(true);
    when(mockLogger.isInfoEnabled()).thenReturn(true);
    when(mockLogger.isDebugEnabled()).thenReturn(true);
    when(mockLogger.isTraceEnabled()).thenReturn(true);
    return mockLogger;
}

From source file:org.mule.module.db.internal.domain.logger.DefaultQueryLoggerFactory.java

@Override
public SingleQueryLogger createQueryLogger(Log logger, QueryTemplate queryTemplate) {
    if (logger.isDebugEnabled()) {
        return new DebugSingleQueryLogger(logger, queryTemplate);
    } else {//w  w  w .j  a v a2 s  . c  om
        return new NullSingleQueryLogger();
    }
}

From source file:org.mule.module.db.internal.domain.logger.DefaultQueryLoggerFactory.java

@Override
public PreparedBulkQueryLogger createBulkQueryLogger(Log logger, QueryTemplate queryTemplate, int bulkSize) {
    if (logger.isDebugEnabled()) {
        return new DebugPreparedBulkQueryLogger(logger, queryTemplate, bulkSize);
    } else {/*from w w w  .  j a  v a2s  . c  om*/
        return new NullPreparedBulkQueryLogger();
    }
}

From source file:org.mule.module.db.internal.domain.logger.DefaultQueryLoggerFactory.java

@Override
public BulkQueryLogger createBulkQueryLogger(Log logger) {
    if (logger.isDebugEnabled()) {
        return new DebugBulkQueryLogger(logger);
    } else {/* w  w w.  ja va2  s. c o  m*/
        return new NullBulkQueryLogger();
    }
}

From source file:org.openadaptor.util.JDBCUtil.java

public static void logCurrentResultSetRow(Log log, String msg, ResultSet rs) throws SQLException {
    if (log.isDebugEnabled()) {
        ResultSetMetaData rsmd = rs.getMetaData();
        if (msg != null) {
            log.debug(msg);//  w w w .  j av a  2 s  .co  m
        }
        for (int i = 1; i <= rsmd.getColumnCount(); i++) {
            log.debug("  " + rsmd.getColumnName(i) + " (" + rsmd.getColumnClassName(i) + ") = "
                    + rs.getString(i));
        }
    }
}

From source file:org.openmrs.module.reportingcompatibility.reporting.export.DataExportUtil.java

/**
 * Auto generated method comment/* w  w w  . jav a2 s  .co  m*/
 * 
 * @param dataExport
 * @param patientSet
 * @param functions
 * @param context
 * @throws Exception
 */
public static void generateExport(DataExportReportObject dataExport, Cohort patientSet,
        DataExportFunctions functions, EvaluationContext context) throws Exception {

    // defining log file here to attempt to reduce memory consumption
    Log log = LogFactory.getLog(DataExportUtil.class);

    VelocityEngine velocityEngine = new VelocityEngine();

    velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
            "org.apache.velocity.runtime.log.CommonsLogLogChute");
    velocityEngine.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME, "dataexport_velocity");

    try {
        velocityEngine.init();
    } catch (Exception e) {
        log.error("Error initializing Velocity engine", e);
    }

    File file = getGeneratedFile(dataExport);
    PrintWriter report = new PrintWriter(file);

    VelocityContext velocityContext = new VelocityContext();

    // Set up list of patients if one wasn't passed into this method
    if (patientSet == null) {
        patientSet = dataExport.generatePatientSet(context);
        functions.setPatientSet(patientSet);
    }

    String sizeGp = Context.getAdministrationService()
            .getGlobalProperty(ReportingCompatibilityConstants.BATCH_SIZE_GP);
    Integer batchSize = ReportingCompatibilityConstants.BATCH_SIZE_GP_DEFAULT;
    try {
        batchSize = Integer.parseInt(sizeGp);
    } catch (Exception e) {
        // Do nothing, just use the default
    }
    functions.setBatchSize(batchSize);

    // add the error handler
    EventCartridge ec = new EventCartridge();
    ec.addEventHandler(new VelocityExceptionHandler());
    velocityContext.attachEventCartridge(ec);

    // Set up velocity utils
    Locale locale = Context.getLocale();
    velocityContext.put("locale", locale);
    velocityContext.put("fn", functions);

    /*
     * If we have any additional velocity objects that need to 
     * be added, do so here.
     */
    if (dataExportKeys != null && dataExportKeys.size() != 0) {
        for (Map.Entry<String, Object> entry : dataExportKeys.entrySet()) {
            velocityContext.put(entry.getKey(), entry.getValue());
        }
    }

    velocityContext.put("patientSet", patientSet);

    String template = dataExport.generateTemplate();

    // check if some deprecated columns are being used in this export
    // warning: hacky.
    if (template.contains("fn.getPatientAttr('Patient', 'tribe')")) {
        throw new APIException("Unable to generate export: " + dataExport.getName()
                + " because it contains a reference to an outdated 'tribe' column.  You must install the 'Tribe Module' into OpenMRS to continue to reference tribes in OpenMRS.");
    }

    if (log.isDebugEnabled())
        log.debug("Template: " + template.substring(0, template.length() < 3500 ? template.length() : 3500)
                + "...");

    try {
        velocityEngine.evaluate(velocityContext, report, DataExportUtil.class.getName(), template);
    } catch (Exception e) {
        log.error("Error evaluating data export " + dataExport.getReportObjectId(), e);
        log.error("Template: " + template.substring(0, template.length() < 3500 ? template.length() : 3500)
                + "...");
        report.print("\n\nError: \n" + e.toString() + "\n Stacktrace: \n");
        e.printStackTrace(report);
    } finally {
        report.close();
        velocityContext.remove("fn");
        velocityContext.remove("patientSet");
        velocityContext = null;

        // reset the ParserPool to something else now?
        // using this to get to RuntimeInstance.init();
        velocityEngine.init();

        velocityEngine = null;

        patientSet = null;
        functions.clear();
        functions = null;
        template = null;
        dataExport = null;
        log.debug("Clearing hibernate session");
        Context.clearSession();

        // clear out the excess objects
        System.gc();
        System.gc();
    }

}

From source file:org.openmrs.reporting.export.DataExportUtil.java

/**
 * Auto generated method comment/*from   w  ww .j a v a 2 s.c  o  m*/
 * 
 * @param dataExport
 * @param patientSet
 * @param functions
 * @param context
 * @throws Exception
 */
public static void generateExport(DataExportReportObject dataExport, Cohort patientSet,
        DataExportFunctions functions, EvaluationContext context) throws Exception {

    // defining log file here to attempt to reduce memory consumption
    Log log = LogFactory.getLog(DataExportUtil.class);

    VelocityEngine velocityEngine = new VelocityEngine();

    velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
            "org.apache.velocity.runtime.log.CommonsLogLogChute");
    velocityEngine.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME, "dataexport_velocity");

    try {
        velocityEngine.init();
    } catch (Exception e) {
        log.error("Error initializing Velocity engine", e);
    }

    File file = getGeneratedFile(dataExport);
    PrintWriter report = new PrintWriter(file);

    VelocityContext velocityContext = new VelocityContext();

    // Set up list of patients if one wasn't passed into this method
    if (patientSet == null) {
        patientSet = dataExport.generatePatientSet(context);
        functions.setAllPatients(dataExport.isAllPatients());
    }

    // add the error handler
    EventCartridge ec = new EventCartridge();
    ec.addEventHandler(new VelocityExceptionHandler());
    velocityContext.attachEventCartridge(ec);

    // Set up velocity utils
    Locale locale = Context.getLocale();
    velocityContext.put("locale", locale);
    velocityContext.put("fn", functions);

    /*
     * If we have any additional velocity objects that need to 
     * be added, do so here.
     */
    if (dataExportKeys != null && dataExportKeys.size() != 0) {
        for (Map.Entry<String, Object> entry : dataExportKeys.entrySet()) {
            velocityContext.put(entry.getKey(), entry.getValue());
        }
    }

    velocityContext.put("patientSet", patientSet);

    String template = dataExport.generateTemplate();

    // check if some deprecated columns are being used in this export
    // warning: hacky.
    if (template.contains("fn.getPatientAttr('Patient', 'tribe')")) {
        throw new APIException("Unable to generate export: " + dataExport.getName()
                + " because it contains a reference to an outdated 'tribe' column.  You must install the 'Tribe Module' into OpenMRS to continue to reference tribes in OpenMRS.");
    }

    if (log.isDebugEnabled())
        log.debug("Template: " + template.substring(0, template.length() < 3500 ? template.length() : 3500)
                + "...");

    try {
        velocityEngine.evaluate(velocityContext, report, DataExportUtil.class.getName(), template);
    } catch (Exception e) {
        log.error("Error evaluating data export " + dataExport.getReportObjectId(), e);
        log.error("Template: " + template.substring(0, template.length() < 3500 ? template.length() : 3500)
                + "...");
        report.print("\n\nError: \n" + e.toString() + "\n Stacktrace: \n");
        e.printStackTrace(report);
    } finally {
        report.close();
        velocityContext.remove("fn");
        velocityContext.remove("patientSet");
        velocityContext = null;

        // reset the ParserPool to something else now?
        // using this to get to RuntimeInstance.init();
        velocityEngine.init();

        velocityEngine = null;

        patientSet = null;
        functions.clear();
        functions = null;
        template = null;
        dataExport = null;
        log.debug("Clearing hibernate session");
        Context.clearSession();

        // clear out the excess objects
        System.gc();
        System.gc();
    }

}

From source file:org.openoss.tip.ri.NetworkServices.java

/**
 *  setter for log/*from   w w w .j a  va 2s.co  m*/
 *  @param Log to use for log messages from this class
 */
@javax.annotation.Resource(name = "tipInterfaceLog")
public void setLog(Log log) {
    if (log == null)
        throw new java.lang.IllegalArgumentException("ERROR: " + this.getClass().getSimpleName()
                + " method: setLog(Log log): Parameter log must not be null");
    this.log = log;
    if (log.isDebugEnabled())
        log.debug("DEBUG: " + this.getClass().getSimpleName() + ": Log set successfully for this class");
}