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

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

Introduction

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

Prototype

void warn(Object message);

Source Link

Document

Logs a message with warn log level.

Usage

From source file:org.apache.tomcat.util.log.CommonLogHandler.java

/**
 * Prints log message and stack trace.//ww  w  .ja  v a 2 s.c  om
 * This method should be overriden by real logger implementations
 *
 * @param   prefix      optional prefix. 
 * @param   message      the message to log. 
 * @param   t      the exception that was thrown.
 * @param   verbosityLevel   what type of message is this?
 *             (WARNING/DEBUG/INFO etc)
 */
public void log(String prefix, String msg, Throwable t, int verbosityLevel) {
    if (prefix == null)
        prefix = "tomcat";

    org.apache.commons.logging.Log l = (org.apache.commons.logging.Log) loggers.get(prefix);
    if (l == null) {
        l = LogFactory.getLog(prefix);
        loggers.put(prefix, l);
    }

    if (verbosityLevel > this.level)
        return;

    if (t == null) {
        if (verbosityLevel == Log.FATAL)
            l.fatal(msg);
        else if (verbosityLevel == Log.ERROR)
            l.error(msg);
        else if (verbosityLevel == Log.WARNING)
            l.warn(msg);
        else if (verbosityLevel == Log.INFORMATION)
            l.info(msg);
        else if (verbosityLevel == Log.DEBUG)
            l.debug(msg);
    } else {
        if (verbosityLevel == Log.FATAL)
            l.fatal(msg, t);
        else if (verbosityLevel == Log.ERROR)
            l.error(msg, t);
        else if (verbosityLevel == Log.WARNING)
            l.warn(msg, t);
        else if (verbosityLevel == Log.INFORMATION)
            l.info(msg, t);
        else if (verbosityLevel == Log.DEBUG)
            l.debug(msg, t);
    }
}

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

private void realLog(final Log log, final String message, final int priority, final Throwable t) {
    final PrintStream tmpOut = System.out;
    final PrintStream tmpErr = System.err;
    System.setOut(out);/*w  w  w  . j av  a  2  s  . c o  m*/
    System.setErr(err);
    switch (priority) {
    case Project.MSG_ERR:
        if (t == null) {
            log.error(message);
        } else {
            log.error(message, t);
        }
        break;
    case Project.MSG_WARN:
        if (t == null) {
            log.warn(message);
        } else {
            log.warn(message, t);
        }
        break;
    case Project.MSG_INFO:
        if (t == null) {
            log.info(message);
        } else {
            log.info(message, t);
        }
        break;
    case Project.MSG_VERBOSE:
        log.debug(message);
        break;
    case Project.MSG_DEBUG:
        log.debug(message);
        break;
    default:
        log.error(message);
        break;
    }
    System.setOut(tmpOut);
    System.setErr(tmpErr);
}

From source file:org.avineas.comli.impl.LinkHandler.java

/**
 * Read a packet from the remote party./*w  ww  . j ava2 s .  c o m*/
 * 
 * @param in The input stream to read from
 * @param timeout The time to wait for a message to appear
 * @param logger The logger to use for debug messages
 * @return The packet read, if any
 * @throws IOException In case of protocol failures
 */
public static Packet read(ReadChannel in, long timeout, Log logger) throws IOException {
    Packet packet = null;
    int number;
    byte[] firstByte = new byte[1];
    while ((number = read(in, firstByte, 0, 1, timeout)) > 0 && firstByte[0] != STX) {
        logger.warn("received spurious byte " + Integer.toHexString(firstByte[0] & 0xff));
    }
    if (number < 0) {
        throw new IOException("end of stream while reading channel");
    }
    if (number > 0) {
        // Read the header away.
        byte[] data = new byte[2 * Packet.MAXSIZE];
        if (read(in, data, 0, Packet.HEADERSIZE, INTERCHARTIMEOUT) == Packet.HEADERSIZE) {
            int offset = Packet.HEADERSIZE;
            packet = new Packet(data, 0, offset);
            // There are three types of packets:
            // - Request type. Consists of address + quantity.
            // - Transfer type. Consists of address + quantity + data.
            // - Acknowledgment. Consists of single ACK.
            // This means that after we checked for an acknowledgment
            // type, we just know the size.
            int remaining;
            if (Packet.isAck(packet.getType())) {
                remaining = 3;
            } else {
                // Need to get the address and the size.
                if (read(in, data, Packet.HEADERSIZE, AddressContents.HEADERSIZE,
                        INTERCHARTIMEOUT) == AddressContents.HEADERSIZE) {
                    offset += AddressContents.HEADERSIZE;
                    AddressContents contents = new AddressContents(data, Packet.HEADERSIZE,
                            AddressContents.HEADERSIZE);
                    int dataSize = contents.getCount();
                    if (Packet.isRequest(packet.getType()))
                        remaining = 2;
                    else
                        remaining = dataSize + 2;
                } else
                    throw new IOException("unexpected timeout while reading packet");
            }
            if (read(in, data, offset, remaining, INTERCHARTIMEOUT) == remaining) {
                // Check the last bytes.
                print(logger, " <-  " + STX, data, 0, offset + remaining);
                if (data[offset + remaining - 2] != ETX) {
                    // Indicate failure.
                    throw new IOException("no ETX found at end of message");
                }
                int bcc = 0;
                for (int cnt = 0; cnt < offset + remaining; cnt++) {
                    bcc ^= data[cnt];
                }
                if (bcc != 0) {
                    throw new IOException("BCC incorrect in packet");
                }
                packet = new Packet(data, 0, offset + remaining - 2);
            } else
                throw new IOException("unexpected timeout while reading remainder of packet");
        }
    }
    return packet;
}

From source file:org.chimi.s4s.config.Log4jConfiguratorTest.java

@Test
public void configure() {
    ByteArrayOutputStream baout = new ByteArrayOutputStream(200);
    PrintStream out = new PrintStream(baout);
    System.setOut(out);/* ww  w.  j av  a 2s .  co  m*/

    System.setProperty(Log4jConfigurator.CONFIG_PATH_SYSTEM_PROPERTY,
            "src/test/resources/org/chimi/s4s/config/test-log4j.properties");
    Log4jConfigurator.configure();

    baout.reset();

    // SLF4J 
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.info("");

    assertEquals("INFO - ", new String(baout.toByteArray()).trim());

    baout.reset();

    // JCL 
    Log log = LogFactory.getLog(getClass());
    log.warn("");

    assertEquals("WARN - ", new String(baout.toByteArray()).trim());
}

From source file:org.displaytag.exception.BaseNestableJspTagException.java

/**
 * Instantiate a new BaseNestableJspTagException.
 * @param source Class where the exception is generated
 * @param message message/*from   w  w w  .  ja  v  a 2s . co  m*/
 */
public BaseNestableJspTagException(Class source, String message) {
    super(message);
    this.sourceClass = source;

    // log exception
    Log log = LogFactory.getLog(source);

    // choose appropriate logging method
    if (getSeverity() == SeverityEnum.DEBUG) {
        log.debug(toString());
    } else if (getSeverity() == SeverityEnum.INFO) {
        log.info(toString());
    } else if (getSeverity() == SeverityEnum.WARN) {
        log.warn(toString());
    } else {
        // error - default
        log.error(toString());
    }

}

From source file:org.displaytag.exception.BaseNestableRuntimeException.java

/**
 * Instantiate a new BaseNestableRuntimeException.
 * @param source Class where the exception is generated
 * @param message message//from ww w.  jav  a2s . c o  m
 */
public BaseNestableRuntimeException(Class source, String message) {
    super(message);
    this.sourceClass = source;

    // log exception
    Log log = LogFactory.getLog(source);

    // choose appropriate logging method
    if (getSeverity() == SeverityEnum.DEBUG) {
        log.debug(toString());
    } else if (getSeverity() == SeverityEnum.INFO) {
        log.info(toString());
    } else if (getSeverity() == SeverityEnum.WARN) {
        log.warn(toString());
    } else {
        // error - default
        log.error(toString());
    }

}

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

/**
 * @param logger//from   www. 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
 *//*from   w  ww  . ja va2 s  .c om*/
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.eclipse.emf.mwe.core.WorkflowEngine.java

private void logIssues(final Log logger, final Issues issues) {
    // log any configuration warning messages
    final Diagnostic[] issueArray = issues.getIssues();
    for (final Diagnostic issue : issueArray) {
        if (issue.getSeverity() == Diagnostic.ERROR) {
            logger.error(issue.toString());
        }/*from   w  w  w. java 2 s  .  c  om*/
        if (issue.getSeverity() == Diagnostic.WARNING) {
            logger.warn(issue.toString());
        }
        if (issue.getSeverity() == Diagnostic.INFO) {
            logger.info(issue.toString());
        }
    }
}

From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.activator.BlueprintContainerProcessor.java

public void preProcessRefresh(final ConfigurableOsgiBundleApplicationContext context) {
    final BundleContext bundleContext = context.getBundleContext();
    // create the ModuleContext adapter
    final BlueprintContainer blueprintContainer = createBlueprintContainer(context);

    // 1. add event listeners
    // add service publisher
    context.addApplicationListener(new BlueprintContainerServicePublisher(blueprintContainer, bundleContext));
    // add waiting event broadcaster
    context.addApplicationListener(new BlueprintWaitingEventDispatcher(context.getBundleContext()));

    // 2. add environmental managers
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        private static final String BLUEPRINT_BUNDLE = "blueprintBundle";
        private static final String BLUEPRINT_BUNDLE_CONTEXT = "blueprintBundleContext";
        private static final String BLUEPRINT_CONTAINER = "blueprintContainer";
        private static final String BLUEPRINT_EXTENDER = "blueprintExtenderBundle";
        private static final String BLUEPRINT_CONVERTER = "blueprintConverter";

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            // lazy logger evaluation
            Log logger = LogFactory.getLog(context.getClass());

            if (!(beanFactory instanceof BeanDefinitionRegistry)) {
                logger.warn("Environmental beans will be registered as singletons instead "
                        + "of usual bean definitions since beanFactory " + beanFactory
                        + " is not a BeanDefinitionRegistry");
            }//from  w  ww  .j  a va2  s  .c  o  m

            // add blueprint container bean
            addPredefinedBlueprintBean(beanFactory, BLUEPRINT_BUNDLE, bundleContext.getBundle(), logger);
            addPredefinedBlueprintBean(beanFactory, BLUEPRINT_BUNDLE_CONTEXT, bundleContext, logger);
            addPredefinedBlueprintBean(beanFactory, BLUEPRINT_CONTAINER, blueprintContainer, logger);
            // addPredefinedBlueprintBean(beanFactory, BLUEPRINT_EXTENDER, extenderBundle, logger);
            addPredefinedBlueprintBean(beanFactory, BLUEPRINT_CONVERTER,
                    new SpringBlueprintConverter(beanFactory), logger);

            // add Blueprint conversion service
            // String[] beans = beanFactory.getBeanNamesForType(BlueprintConverterConfigurer.class, false, false);
            // if (ObjectUtils.isEmpty(beans)) {
            // beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
            // }
            beanFactory.setConversionService(
                    new SpringBlueprintConverterService(beanFactory.getConversionService(), beanFactory));
        }

        private void addPredefinedBlueprintBean(ConfigurableListableBeanFactory beanFactory, String beanName,
                Object value, Log logger) {
            if (!beanFactory.containsLocalBean(beanName)) {
                logger.debug("Registering pre-defined bean named " + beanName);
                if (beanFactory instanceof BeanDefinitionRegistry) {
                    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

                    GenericBeanDefinition def = new GenericBeanDefinition();
                    def.setBeanClass(ENV_FB_CLASS);
                    ConstructorArgumentValues cav = new ConstructorArgumentValues();
                    cav.addIndexedArgumentValue(0, value);
                    def.setConstructorArgumentValues(cav);
                    def.setLazyInit(false);
                    def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
                    registry.registerBeanDefinition(beanName, def);

                } else {
                    beanFactory.registerSingleton(beanName, value);
                }

            } else {
                logger.warn("A bean named " + beanName
                        + " already exists; aborting registration of the predefined value...");
            }
        }
    });

    // 3. add cycle breaker
    context.addBeanFactoryPostProcessor(cycleBreaker);

    BlueprintEvent creatingEvent = new BlueprintEvent(BlueprintEvent.CREATING, context.getBundle(),
            extenderBundle);
    listenerManager.blueprintEvent(creatingEvent);
    dispatcher.beforeRefresh(creatingEvent);
}