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

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

Introduction

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

Prototype

boolean isTraceEnabled();

Source Link

Document

Is trace logging currently enabled?

Usage

From source file:org.apache.tools.ant.listener.CommonsLoggingListener.java

/** {@inheritDoc}. */
public void taskFinished(final BuildEvent event) {
    if (initialized) {
        final Task task = event.getTask();
        Object real = task;/* w w  w  .j av  a 2  s.  c om*/
        if (task instanceof UnknownElement) {
            final Object realObj = ((UnknownElement) task).getTask();
            if (realObj != null) {
                real = realObj;
            }
        }
        final Log log = getLog(real.getClass().getName(), null);
        if (event.getException() == null) {
            if (log.isTraceEnabled()) {
                realLog(log, "Task \"" + task.getTaskName() + "\" finished.", Project.MSG_VERBOSE, null);
            }
        } else {
            realLog(log, "Task \"" + task.getTaskName() + "\" finished with error.", Project.MSG_ERR,
                    event.getException());
        }
    }
}

From source file:org.easyrec.utils.spring.log.LoggerUtils.java

/**
 * @param logger/*from  w w  w . j a  v a 2  s. co  m*/
 * @param logLevel
 *
 */
public static boolean isLogLevelEnabled(Log logger, String logLevel) {
    if (logLevel.equalsIgnoreCase("info")) {
        if (logger.isInfoEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("debug")) {
        if (logger.isDebugEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("error")) {
        if (logger.isErrorEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("trace")) {
        if (logger.isTraceEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("warn")) {
        if (logger.isWarnEnabled()) {
            return true;
        }
    } else if (logLevel.equalsIgnoreCase("fatal")) {
        if (logger.isFatalEnabled()) {
            return true;
        }
    } else {
        logger.warn("Passed unknown log level '" + logLevel + "' to Aspect - returning false!");
        return false;
    }
    logger.warn("log level '" + logLevel + "' not enabled - returning false!");
    return false;
}

From source file:org.easyrec.utils.spring.log.LoggerUtils.java

/**
 * Writes the given 'message' to the Log 'logger' with level 'logLevel'.
 *
 * @param logger   the Log to which the message is written
 * @param logLevel the level to which the message is written
 * @param message  the message to be written
 */// ww w . j  av  a 2s .  c  o  m
public static void log(Log logger, String logLevel, String message) {
    if (logLevel.equalsIgnoreCase("info")) {
        if (logger.isInfoEnabled()) {
            logger.info(message);
        }
    } else if (logLevel.equalsIgnoreCase("debug")) {
        if (logger.isDebugEnabled()) {
            logger.debug(message);
        }
    } else if (logLevel.equalsIgnoreCase("error")) {
        if (logger.isErrorEnabled()) {
            logger.error(message);
        }
    } else if (logLevel.equalsIgnoreCase("trace")) {
        if (logger.isTraceEnabled()) {
            logger.trace(message);
        }
    } else if (logLevel.equalsIgnoreCase("warn")) {
        if (logger.isWarnEnabled()) {
            logger.warn(message);
        }
    } else if (logLevel.equalsIgnoreCase("fatal")) {
        if (logger.isFatalEnabled()) {
            logger.fatal(message);
        }
    } else {
        logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!");
        logger.error(message);
    }
}

From source file:org.easyrec.utils.spring.log.LoggerUtils.java

/**
 * Writes the given 'message' to the Log 'logger' with level 'logLevel'.
 *
 * @param logger   the Log to which the message is written
 * @param logLevel the level to which the message is written
 * @param message  the message to be written
 * @param ta       a Throwable passed on to the Log
 *//*w w w  . ja  va2s. c  o m*/
public static void log(Log logger, String logLevel, String message, Throwable ta) {
    if (logLevel.equalsIgnoreCase("info")) {
        if (logger.isInfoEnabled()) {
            logger.info(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("debug")) {
        if (logger.isDebugEnabled()) {
            logger.debug(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("error")) {
        if (logger.isErrorEnabled()) {
            logger.error(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("trace")) {
        if (logger.isTraceEnabled()) {
            logger.trace(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("warn")) {
        if (logger.isWarnEnabled()) {
            logger.warn(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("fatal")) {
        if (logger.isFatalEnabled()) {
            logger.fatal(message, ta);
        }
    } else {
        logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!");
        logger.error(message, ta);
    }
}

From source file:org.elasticsearch.hadoop.cascading.EsHadoopScheme.java

@Override
public void sinkConfInit(FlowProcess<JobConf> flowProcess, Tap<JobConf, RecordReader, OutputCollector> tap,
        JobConf conf) {//from  www .j  av  a 2 s. c om

    conf.setOutputFormat(EsOutputFormat.class);
    // define an output dir to prevent Cascading from setting up a TempHfs and overriding the OutputFormat
    Settings set = loadSettings(conf, false);

    Log log = LogFactory.getLog(EsTap.class);
    InitializationUtils.setValueWriterIfNotSet(set, CascadingValueWriter.class, log);
    InitializationUtils.setValueReaderIfNotSet(set, JdkValueReader.class, log);
    InitializationUtils.setBytesConverterIfNeeded(set, CascadingLocalBytesConverter.class, log);
    InitializationUtils.setFieldExtractorIfNotSet(set, CascadingFieldExtractor.class, log);

    // NB: we need to set this property even though it is not being used - and since and URI causes problem, use only the resource/file
    //conf.set("mapred.output.dir", set.getTargetUri() + "/" + set.getTargetResource());
    HadoopCfgUtils.setFileOutputFormatDir(conf, set.getResourceWrite());
    HadoopCfgUtils.setOutputCommitterClass(conf, EsOutputFormat.EsOldAPIOutputCommitter.class.getName());

    if (log.isTraceEnabled()) {
        log.trace("Initialized (sink) configuration " + HadoopCfgUtils.asProperties(conf));
    }
}

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

/**
 * Wraps {@link Log#trace(String)}// w  w w. j  a  v  a  2  s. c om
 * 
 * @param pattern to format against
 * @param objs an array of objects used as parameters to the <code>pattern</code>
 */
public static final void trace(Object... objs) {
    Log log = getLogger();
    if (log.isTraceEnabled()) {
        log.trace(getMessage(objs));
    }
}

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.openspaces.grid.gsm.machines.MachinesSlaUtils.java

public static Collection<GridServiceAgent> sortAndFilterAgents(GridServiceAgent[] agents,
        ElasticMachineProvisioningConfig machineProvisioningConfig, Log logger) {
    Set<GridServiceAgent> filteredAgents = new LinkedHashSet<GridServiceAgent>(); //maintain order
    for (final GridServiceAgent agent : agents) {
        if (!agent.isDiscovered()) {
            if (logger.isDebugEnabled()) {
                logger.debug(//w ww .  j  a  va2s.  c o  m
                        "Agent " + MachinesSlaUtils.machineToString(agent.getMachine()) + " has shutdown.");
            }
        } else if (!MachinesSlaUtils.isAgentConformsToMachineProvisioningConfig(agent,
                machineProvisioningConfig)) {
            if (logger.isDebugEnabled()) {
                agent.getExactZones().isStasfies(machineProvisioningConfig.getGridServiceAgentZones());

                ExactZonesConfig agentZones = agent.getExactZones();
                ZonesConfig puZones = machineProvisioningConfig.getGridServiceAgentZones();
                boolean isDedicatedManagedmentMachines = machineProvisioningConfig
                        .isDedicatedManagementMachines();
                boolean isManagementRunningOnMachine = MachinesSlaUtils
                        .isManagementRunningOnMachine(agent.getMachine());

                StringBuilder logMessage = new StringBuilder();
                logMessage.append("Agent ").append(MachinesSlaUtils.machineToString(agent.getMachine()))
                        .append(" does not conform to machine provisioning SLA. ").append("Agent zones: ")
                        .append(agentZones).append(",").append("PU zones: ").append(puZones).append(", ")
                        .append("Is dedicated management machines: ").append(isDedicatedManagedmentMachines)
                        .append(", ").append("Is management running on machine: ")
                        .append(isManagementRunningOnMachine);

                logger.debug(logMessage.toString());
            }
        } else {
            if (logger.isTraceEnabled()) {
                logger.trace("Agent " + MachinesSlaUtils.machineToString(agent.getMachine())
                        + " conforms to machine provisioning SLA.");
            }
            filteredAgents.add(agent);
        }
    }
    //TODO: Move this sort into the bin packing solver. It already has the priority of each machine
    // so it can sort it by itself.
    final List<GridServiceAgent> sortedFilteredAgents = MachinesSlaUtils.sortManagementFirst(filteredAgents);
    if (logger.isDebugEnabled()) {
        logger.debug("Provisioned Agents: " + MachinesSlaUtils.machinesToString(sortedFilteredAgents));
    }
    return sortedFilteredAgents;
}

From source file:org.rhq.enterprise.gui.admin.home.AdminHomePortalAction.java

/**
 * Set up the Admin Home portal.//from   w  w w.ja  v  a 2  s  .  c om
 */
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(AdminHomePortalAction.class.getName());

    Portal portal = Portal.createPortal(TITLE_HOME, PORTLET_HOME);
    request.setAttribute(Constants.PORTAL_KEY, portal);

    String returnPath = ActionUtils.findReturnPath(mapping, null);
    if (log.isTraceEnabled()) {
        log.trace("setting return path: " + returnPath);
    }

    SessionUtils.setReturnPath(request.getSession(), returnPath);

    return null;
}

From source file:org.springframework.amqp.rabbit.core.RabbitTemplateIntegrationTests.java

@Test
public void testAtomicSendAndReceiveExternalExecutor() throws Exception {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor();
    final String execName = "make-sure-exec-passed-in";
    exec.setBeanName(execName);/*www .j  av  a 2  s.com*/
    exec.afterPropertiesSet();
    connectionFactory.setExecutor(exec);
    final Field[] fields = new Field[1];
    ReflectionUtils.doWithFields(RabbitTemplate.class, new FieldCallback() {
        public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
            field.setAccessible(true);
            fields[0] = field;
        }
    }, new FieldFilter() {
        public boolean matches(Field field) {
            return field.getName().equals("logger");
        }
    });
    Log logger = Mockito.mock(Log.class);
    when(logger.isTraceEnabled()).thenReturn(true);

    final AtomicBoolean execConfiguredOk = new AtomicBoolean();

    doAnswer(new Answer<Object>() {
        public Object answer(InvocationOnMock invocation) throws Throwable {
            String log = (String) invocation.getArguments()[0];
            if (log.startsWith("Message received") && Thread.currentThread().getName().startsWith(execName)) {
                execConfiguredOk.set(true);
            }
            return null;
        }
    }).when(logger).trace(Mockito.anyString());
    final RabbitTemplate template = new RabbitTemplate(connectionFactory);
    ReflectionUtils.setField(fields[0], template, logger);
    template.setRoutingKey(ROUTE);
    template.setQueue(ROUTE);
    ExecutorService executor = Executors.newFixedThreadPool(1);
    // Set up a consumer to respond to our producer
    Future<Message> received = executor.submit(new Callable<Message>() {

        public Message call() throws Exception {
            Message message = null;
            for (int i = 0; i < 10; i++) {
                message = template.receive();
                if (message != null) {
                    break;
                }
                Thread.sleep(100L);
            }
            assertNotNull("No message received", message);
            template.send(message.getMessageProperties().getReplyTo(), message);
            return message;
        }

    });
    Message message = new Message("test-message".getBytes(), new MessageProperties());
    Message reply = template.sendAndReceive(message);
    assertEquals(new String(message.getBody()),
            new String(received.get(1000, TimeUnit.MILLISECONDS).getBody()));
    assertNotNull("Reply is expected", reply);
    assertEquals(new String(message.getBody()), new String(reply.getBody()));
    // Message was consumed so nothing left on queue
    reply = template.receive();
    assertEquals(null, reply);

    assertTrue(execConfiguredOk.get());
}