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, Throwable t);

Source Link

Document

Logs an error with warn log level.

Usage

From source file:net.darkmist.clf.Util.java

public static <T extends Closeable> T close(T toClose, Log logExceptionTo, String name) {
    if (toClose == null)
        return null;
    try {//  ww w.ja v  a2  s. c o m
        toClose.close();
    } catch (IOException e) {
        logExceptionTo.warn("IOException closing " + name + " ignored.", e);
    }
    return null;
}

From source file:com.runwaysdk.logging.RunwayLogUtil.java

public static void logToLevel(Log log, LogLevel level, String msg, Throwable t) {
    if (level == LogLevel.TRACE) {
        log.trace(msg, t);//  w  w w.j a  va 2 s. c  o  m
    } else if (level == LogLevel.DEBUG) {
        log.debug(msg, t);
    } else if (level == LogLevel.INFO) {
        log.info(msg, t);
    } else if (level == LogLevel.WARN) {
        log.warn(msg, t);
    } else if (level == LogLevel.ERROR) {
        log.error(msg, t);
    } else if (level == LogLevel.FATAL) {
        log.fatal(msg, t);
    } else {
        log.fatal(
                "RunwayLogUtil.logToLevel was called, but an invalid level was specified. Here is the message we were passed: '"
                        + msg + "'");
    }
}

From source file:edu.vt.middleware.crypt.util.CryptReader.java

/**
 * Attempts to create a Bouncy Castle <code>DERObject</code> from a byte array
 * representing ASN.1 encoded data.//from   ww  w. j a  va  2  s .  c o  m
 *
 * @param  data  ASN.1 encoded data as byte array.
 * @param  discardWrapper  In some cases the value of the encoded data may
 * itself be encoded data, where the latter encoded data is desired. Recall
 * ASN.1 data is of the form {TAG, SIZE, DATA}. Set this flag to true to skip
 * the first two bytes, e.g. TAG and SIZE, and treat the remaining bytes as
 * the encoded data.
 *
 * @return  DER object.
 *
 * @throws  IOException  On I/O errors.
 */
public static DERObject readEncodedBytes(final byte[] data, final boolean discardWrapper) throws IOException {
    final ByteArrayInputStream inBytes = new ByteArrayInputStream(data);
    int size = data.length;
    if (discardWrapper) {
        inBytes.skip(2);
        size = data.length - 2;
    }

    final ASN1InputStream in = new ASN1InputStream(inBytes, size);
    try {
        return in.readObject();
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            final Log logger = LogFactory.getLog(CryptReader.class);
            if (logger.isWarnEnabled()) {
                logger.warn("Error closing ASN.1 input stream.", e);
            }
        }
    }
}

From source file:edu.vt.middleware.crypt.util.CryptReader.java

/**
 * Reads all the data in the given stream and returns the contents as a byte
 * array./* ww w  . j a  va  2 s .c  o  m*/
 *
 * @param  in  Input stream to read.
 *
 * @return  Entire contents of stream.
 *
 * @throws  IOException  On read errors.
 */
private static byte[] readData(final InputStream in) throws IOException {
    final byte[] buffer = new byte[BUFFER_SIZE];
    final ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE);
    int count = 0;
    try {
        while ((count = in.read(buffer, 0, BUFFER_SIZE)) > 0) {
            bos.write(buffer, 0, count);
        }
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            final Log logger = LogFactory.getLog(CryptProvider.class);
            if (logger.isWarnEnabled()) {
                logger.warn("Error closing input stream.", e);
            }
        }
    }
    return bos.toByteArray();
}

From source file:it.cnr.icar.eric.client.ui.thin.OutputExceptions.java

/**
 * Log exceptions and display them to user in a consistent fashion.
 *
 * @param log Log where error or warning should be output
 * @param logMsg Context message to log with t
 * @param displayMsg Context message to display to user with t
 * @param t Throwable to log about and optionally display
 * @param display Output information about this Throwable on page?
 * @param warning If true, log warning rather than error
 */// ww  w.j  a  va2s  . co m
private static void display(Log log, String logMsg, String displayMsg, Throwable t, boolean display,
        boolean warning) {
    // When not given a Msg, should we provide context for cause?
    boolean needContext = (null != t.getMessage() && null != t.getCause());

    // Log a fair amount of information unconditionally
    if (null == logMsg && null != displayMsg) {
        logMsg = displayMsg;
    }
    if (log.isDebugEnabled()) {
        // Include full traceback in logging output
        if (null == logMsg) {
            if (warning) {
                log.warn(t.toString(), t);
            } else {
                log.error(t.toString(), t);
            }
        } else {
            if (warning) {
                log.warn(logMsg, t);
            } else {
                log.error(logMsg, t);
            }
        }
    } else {
        if (null == logMsg) {
            if (needContext) {
                if (warning) {
                    log.warn(t.toString());
                } else {
                    log.error(t.toString());
                }
            }
        } else {
            if (warning) {
                log.warn(logMsg);
            } else {
                log.error(logMsg);
            }
        }
        if (warning) {
            log.error(getCause(t, true));
        } else {
            log.error(getCause(t, true));
        }
    }

    // Conditionally display a subset of the above information to the user
    if (display) {
        FacesContext context = FacesContext.getCurrentInstance();
        FacesMessage.Severity severity = (warning ? FacesMessage.SEVERITY_ERROR : FacesMessage.SEVERITY_WARN);

        if (null == displayMsg && null != logMsg) {
            displayMsg = logMsg;
        }
        if (null == displayMsg) {
            if (needContext) {
                context.addMessage(null, new FacesMessage(severity, goodMessage(t), null));
            }
        } else {
            context.addMessage(null, new FacesMessage(severity, displayMsg, null));
        }
        context.addMessage(null, new FacesMessage(severity, getCause(t, false), null));
    }
}

From source file:kr.co.bitnine.octopus.util.StringUtils.java

/**
 * Print a log message for starting up and shutting down
 *
 * @param clazz the class of the server// www.j  ava2s  . c om
 * @param args  arguments
 * @param log   the target log object
 */
public static void startupShutdownMessage(Class<?> clazz, String[] args, final Log log) {
    final String classname = clazz.getSimpleName();
    final String hostname = NetUtils.getHostname();

    final String build = VersionInfo.getUrl() + ", rev. " + VersionInfo.getRevision() + "; compiled by '"
            + VersionInfo.getUser() + "' on " + VersionInfo.getDate();
    String[] msg = new String[] { "Starting " + classname, "  host = " + hostname,
            "  args = " + Arrays.asList(args), "  version = " + VersionInfo.getVersion(),
            "  classpath = " + System.getProperty("java.class.path"), "  build = " + build,
            "  java = " + System.getProperty("java.version") };
    log.info(toStartupShutdownString("STARTUP_MSG: ", msg));

    if (SystemUtils.IS_OS_UNIX) {
        try {
            SignalLogger.INSTANCE.register(log);
        } catch (Throwable t) {
            log.warn("failed to register any UNIX signal loggers: ", t);
        }
    }
    ShutdownHookManager.get().addShutdownHook(new Runnable() {
        @Override
        public void run() {
            log.info(toStartupShutdownString("SHUTDOWN_MSG: ",
                    new String[] { "Shutting down " + classname + " at " + hostname }));
        }
    }, SHUTDOWN_HOOK_PRIORITY);
}

From source file:net.sf.nmedit.nomad.core.jpf.JPFServiceInstallerTool.java

private static void activateService(Log log, Map<String, Class<Service>> serviceClassCache, Extension extension,
        ClassLoader pluginClassLoader) {
    String serviceClassName = extension.getParameter(SERVICE_CLASS_KEY).valueAsString();

    String implementationClassName = extension.getParameter(SERVICE_IMPLEMENTATION_CLASS_KEY).valueAsString();

    if (log.isInfoEnabled()) {
        String description = extension.getParameter(SERVICE_DESCRIPTION_KEY).valueAsString();

        log.info("Service implementation / Service: " + implementationClassName + " (description=" + description
                + ") / " + serviceClassName);
    }// ww w  .j a v a  2  s. com

    Class<Service> serviceClass;
    try {
        serviceClass = lookupServiceClass(serviceClassCache, serviceClassName, pluginClassLoader);
    } catch (ClassNotFoundException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error loading service class: " + serviceClassName, e);
        }

        return;
    }

    Class<Service> serviceImplementationClass;
    try {
        serviceImplementationClass = lookupServiceImplementationClass(serviceClass, implementationClassName,
                pluginClassLoader);
    } catch (ClassNotFoundException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error loading service implementation class: " + implementationClassName, e);
        }
        return;
    }

    Service serviceInstance;
    try {
        serviceInstance = serviceImplementationClass.newInstance();
    } catch (InstantiationException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error instantiating service: " + serviceImplementationClass, e);
        }

        return;
    } catch (IllegalAccessException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error instantiating service: " + serviceImplementationClass, e);
        }

        return;
    }

    try {
        ServiceRegistry.addService(serviceClass, serviceInstance);
    } catch (ServiceException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error installing service: " + serviceInstance, e);
        }

        return;
    }
}

From source file:hadoopInstaller.logging.CompositeLog.java

@Override
public void warn(Object message, Throwable t) {
    for (Log log : this.logs) {
        log.warn(message, t);
    }//from w  ww  . ja v a 2  s  .  com
}

From source file:gaderian.test.services.TestThreadEventNotifier.java

public void testListenerThrowsException() {
    Log log = (Log) createMock(Log.class);

    final RuntimeException re = new RuntimeException("Listener Failure");

    log.warn("Thread cleanup exception: Listener Failure", re);

    replayAllRegisteredMocks();// www . jav  a2s  .  com

    ThreadCleanupListener l = new ThreadCleanupListener() {
        public void threadDidCleanup() {
            throw re;
        }
    };

    ThreadEventNotifier n = new ThreadEventNotifierImpl(log);

    n.addThreadCleanupListener(l);

    n.fireThreadCleanup();

    verifyAllRegisteredMocks();
}

From source file:io.netty.logging.CommonsLoggerTest.java

@Test
public void testWarnWithException() {
    Log mock = createStrictMock(Log.class);

    mock.warn("a", e);
    replay(mock);//from  w w  w  .  j a  v  a2s.c om

    InternalLogger logger = new CommonsLogger(mock, "foo");
    logger.warn("a", e);
    verify(mock);
}