Example usage for java.util.logging Logger severe

List of usage examples for java.util.logging Logger severe

Introduction

In this page you can find the example usage for java.util.logging Logger severe.

Prototype

public void severe(Supplier<String> msgSupplier) 

Source Link

Document

Log a SEVERE message, which is only to be constructed if the logging level is such that the message will actually be logged.

Usage

From source file:net.roboconf.agent.internal.misc.UserDataUtils.java

/**
 * Configures the agent from a IaaS registry.
 * @param logger a logger/* w w w. j av  a 2s  . c  om*/
 * @return the agent's data, or null if they could not be parsed
 */
public static AgentProperties findParametersForAmazonOrOpenStack(Logger logger) {

    // Copy the user data
    String userData = "";
    InputStream in = null;
    try {
        URL userDataUrl = new URL("http://169.254.169.254/latest/user-data");
        in = userDataUrl.openStream();
        ByteArrayOutputStream os = new ByteArrayOutputStream();

        Utils.copyStreamSafely(in, os);
        userData = os.toString("UTF-8");

    } catch (IOException e) {
        logger.severe("The agent properties could not be read. " + e.getMessage());
        Utils.logException(logger, e);
    }

    AgentProperties result = null;
    in = null;
    try {
        // Parse the user data
        result = AgentProperties.readIaasProperties(userData, logger);

        // We need to ask our IP address because we may have several network interfaces.
        URL userDataUrl = new URL("http://169.254.169.254/latest/meta-data/public-ipv4");
        in = userDataUrl.openStream();
        ByteArrayOutputStream os = new ByteArrayOutputStream();

        Utils.copyStreamSafely(in, os);
        String ip = os.toString("UTF-8");
        if (!AgentUtils.isValidIP(ip)) {
            // Failed retrieving public IP: try private one instead
            Utils.closeQuietly(in);
            userDataUrl = new URL("http://169.254.169.254/latest/meta-data/local-ipv4");
            in = userDataUrl.openStream();
            os = new ByteArrayOutputStream();

            Utils.copyStreamSafely(in, os);
            ip = os.toString("UTF-8");
        }

        if (!AgentUtils.isValidIP(ip))
            throw new IOException("No IP address could be retrieved (either public-ipv4 or local-ipv4)");

        result.setIpAddress(os.toString("UTF-8"));

    } catch (IOException e) {
        logger.severe("The network properties could not be read. " + e.getMessage());
        Utils.logException(logger, e);

    } finally {
        Utils.closeQuietly(in);
    }

    return result;
}

From source file:controllers.loggers.LogController.java

@Route(method = HttpMethod.GET, uri = "/log/jul")
public Result jul(@Parameter("message") String message) {
    final Logger logger = Logger.getLogger(LogController.class.getName());
    logger.severe(message);
    return ok();/* www. j  a v a  2 s.c om*/
}

From source file:org.noroomattheinn.utils.Utils.java

public static void setupLogger(File where, String basename, Logger logger, Level level) {
    rotateLogs(where, basename, 3);/*from w w w.  j  av  a  2s.com*/

    FileHandler fileHandler;
    try {
        logger.setLevel(level);
        fileHandler = new FileHandler((new File(where, basename + "-00.log")).getAbsolutePath());
        fileHandler.setFormatter(new SimpleFormatter());
        fileHandler.setLevel(level);
        logger.addHandler(fileHandler);

        for (Handler handler : Logger.getLogger("").getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                handler.setLevel(level);
            }
        }
    } catch (IOException | SecurityException ex) {
        logger.severe("Unable to establish log file: " + ex);
    }
}

From source file:org.springframework.boot.logging.log4j.Log4JLoggingSystemTests.java

@Test
@Ignore("Fails on Bamboo")
public void loggingThatUsesJulIsCaptured() {
    this.loggingSystem.beforeInitialize();
    this.loggingSystem.initialize(null, null, null);
    java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(getClass().getName());
    julLogger.severe("Hello world");
    String output = this.output.toString().trim();
    assertTrue("Wrong output:\n" + output, output.contains("Hello world"));
}

From source file:jp.ikedam.jenkins.plugins.ldap_sasl.SearchUserDnResolver.java

/**
 * Resolve the user DN by querying the LDAP directory.
 * //  ww w.ja va  2s  .co  m
 * @param ctx LDAP context, already authenticated.
 * @param username the username the user authenticated with.
 * 
 * @return the DN of the user.
 * @see jp.ikedam.jenkins.plugins.ldap_sasl.UserDnResolver#getUserDn(javax.naming.ldap.LdapContext, java.lang.String)
 */
@Override
public String getUserDn(LdapContext ctx, String username) {
    Logger logger = getLogger();
    if (StringUtils.isBlank(getSearchQueryTemplate())) {
        // not configured.
        logger.severe("Not configured.");

        return null;
    }

    try {
        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        logger.fine(String.format("Searching users base=%s, username=%s", getSearchBase(), username));
        String query = expandUsername(getSearchQueryTemplate(), username);
        NamingEnumeration<SearchResult> entries = ctx.search((getSearchBase() != null) ? getSearchBase() : "",
                query, searchControls);
        if (!entries.hasMore()) {
            // no entry.
            logger.severe(String.format("User not found: %s", username));
            return null;
        }

        String userDn = entries.next().getNameInNamespace();

        if (entries.hasMore()) {
            // more than one entry.
            logger.severe(String.format("User found more than one: %s", username));
            return null;
        }
        entries.close();

        return userDn;
    } catch (NamingException e) {
        logger.log(Level.SEVERE, "Failed to search a user", e);
        return null;
    }
}

From source file:mockit.integration.logging.LoggingIntegrationsTest.java

@Test
public void jdkLoggingShouldLogNothing() {
    Logger log1 = Logger.getAnonymousLogger();
    Logger log2 = Logger.getAnonymousLogger("bundle");
    Logger log3 = Logger.getLogger(LoggingIntegrationsTest.class.getName());
    Logger log4 = Logger.getLogger(LoggingIntegrationsTest.class.getName(), "bundle");

    assertFalse(log1.isLoggable(Level.ALL));
    log1.severe("testing that logger does nothing");
    log2.setLevel(Level.WARNING);
    log2.info("testing that logger does nothing");
    log3.warning("testing that logger does nothing");
    log4.fine("testing that logger does nothing");
    log4.finest("testing that logger does nothing");
}

From source file:com.qualogy.qafe.core.errorhandling.ErrorProcessor.java

private static void logError(ErrorHandler errorHandler, ApplicationContext context, DataIdentifier dataId,
        Logger log) {
    if ((errorHandler.getErrorRef() != null) && (errorHandler.getErrorRef().getRef() != null)) {
        ServiceError serviceError = errorHandler.getErrorRef().getRef();
        if (serviceError.getLoggingSettings() != null) {
            String message = "";
            String messageKey = serviceError.getLoggingSettings().getMessageKey();
            if (messageKey != null) {
                message += MessagesHandler.getMessage(context, dataId, messageKey);
            }//from  www  . j  a v a  2 s.  c o  m
            String solutionKey = serviceError.getLoggingSettings().getSolutionKey();
            if (solutionKey != null) {
                message += MessagesHandler.getMessage(context, dataId, solutionKey);
            }
            String errorMessage = serviceError.getLoggingSettings().getErrorMessage();
            if (StringUtils.isBlank(message) && (errorMessage != null)) {
                message += errorMessage;
            }
            if (!StringUtils.isBlank(message)) {
                log.severe(message);
            }
        }
    }
}

From source file:es.upm.dit.gsi.barmas.dataset.utils.DatasetSplitter.java

private void copyFileUsingApacheCommonsIO(File source, File dest, Logger logger) {
    try {//from   w  w  w .ja  va  2  s. c  o m
        FileUtils.copyFile(source, dest);
    } catch (IOException e) {
        logger.severe("Problems copying file noEssentials");
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:org.blazr.extrastorage.ExtraStorage.java

public void onDisable() {
    Logger log = getLogger();
    try {//from   w  w w. j  av a2  s  .c o  m
        IO.save(this);
    } catch (Exception e) {
        log.severe("Error saving inventories during disable! Backpacks may not be saved properly!");
        e.printStackTrace();
    }
    log.info("Disabled!");
}

From source file:org.geoserver.wfs.json.JSONType.java

/**
 * Handle Exception in JSON and JSONP format
 * /*from w  ww . ja  va 2s  .c om*/
 * @param LOGGER the logger to use (can be null)
 * @param exception the exception to write to the response outputStream
 * @param request the request generated the exception
 * @param charset the desired charset
 * @param verbose be verbose
 * @param isJsonp switch writing json (false) or jsonp (true)
 */
public static void handleJsonException(Logger LOGGER, ServiceException exception, Request request,
        String charset, boolean verbose, boolean isJsonp) {

    final HttpServletResponse response = request.getHttpResponse();
    // TODO: server encoding options?
    response.setCharacterEncoding(charset);

    ServletOutputStream os = null;
    try {
        os = response.getOutputStream();
        if (isJsonp) {
            // jsonp
            response.setContentType(JSONType.jsonp);
            JSONType.writeJsonpException(exception, request, os, charset, verbose);
        } else {
            // json
            OutputStreamWriter outWriter = null;
            try {
                outWriter = new OutputStreamWriter(os, charset);
                response.setContentType(JSONType.json);
                JSONType.writeJsonException(exception, request, outWriter, verbose);
            } finally {
                if (outWriter != null) {
                    try {
                        outWriter.flush();
                    } catch (IOException ioe) {
                    }
                    IOUtils.closeQuietly(outWriter);
                }
            }

        }
    } catch (Exception e) {
        if (LOGGER != null && LOGGER.isLoggable(Level.SEVERE))
            LOGGER.severe(e.getLocalizedMessage());
    } finally {
        if (os != null) {
            try {
                os.flush();
            } catch (IOException ioe) {
            }
            IOUtils.closeQuietly(os);
        }
    }
}