Java Code Examples for java.util.logging.Logger#severe()

The following examples show how to use java.util.logging.Logger#severe() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestIsLoggable.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void loglevel(Level l, Logger logger, String message) {
    LogTest test = LogTest.valueOf("LEV_"+l.getName());
    switch(test) {
        case LEV_SEVERE:
            logger.severe(message);
            break;
        case LEV_WARNING:
            logger.warning(message);
            break;
        case LEV_INFO:
            logger.info(message);
            break;
        case LEV_CONFIG:
            logger.config(message);
            break;
        case LEV_FINE:
            logger.fine(message);
            break;
        case LEV_FINER:
            logger.finer(message);
            break;
        case LEV_FINEST:
            logger.finest(message);
            break;
    }
}
 
Example 2
Source File: LogLevelTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@Test
    public void testLogLevelInAppLogLineMatchesActualLogLevelUsedWhenLogging() {
        Logger log = Logger.getLogger(LogLevelTest.class.getName());
        log.finest("finest_testLogLevelMatches");
        log.finer("finer_testLogLevelMatches");
        log.fine("fine_testLogLevelMatches");
        log.config("config_testLogLevelMatches");
        log.info("info_testLogLevelMatches");
        log.warning("warning_testLogLevelMatches");
        log.severe("severe_testLogLevelMatches");
        flush(log);

        assertLogContains("finest_testLogLevelMatches", LogService.LogLevel.DEBUG);
        assertLogContains("finer_testLogLevelMatches", LogService.LogLevel.DEBUG);
        assertLogContains("fine_testLogLevelMatches", LogService.LogLevel.DEBUG);
        assertLogContains("config_testLogLevelMatches", LogService.LogLevel.DEBUG);

        // we can't test the following on dev appserver, because it returns incorrect logLevels
        // more info at http://code.google.com/p/googleappengine/issues/detail?id=8651
        //TODO:Renable after project compiles and runs.
//        assertLogContains("info_testLogLevelMatches", LogService.LogLevel.INFO);
//        assertLogContains("warning_testLogLevelMatches", LogService.LogLevel.WARN);
//        assertLogContains("severe_testLogLevelMatches", LogService.LogLevel.ERROR);
    }
 
Example 3
Source File: NodeManager.java    From lancoder with GNU General Public License v3.0 6 votes vote down vote up
private String getNewUNID(Node n) {
	String algorithm = Master.ALGORITHM;
	String result = "";
	long ms = System.currentTimeMillis();
	String input = ms + n.getName();
	MessageDigest md = null;

	try {
		md = MessageDigest.getInstance(algorithm);
	} catch (NoSuchAlgorithmException e) {
		// print and handle exception
		// if a null string is given back to the client, it won't connect
		Logger logger = Logger.getLogger("lancoder");
		logger.severe(String.format("Could not get an instance of %s to produce a UNID.%n", algorithm));
		logger.severe(e.getMessage());

		return "";
	}
	byte[] byteArray = md.digest(input.getBytes());
	result = "";
	for (int i = 0; i < byteArray.length; i++) {
		result += Integer.toString((byteArray[i] & 0xff) + 0x100, 16).substring(1);
	}
	return result;
}
 
Example 4
Source File: LoggingServlet.java    From appengine-java-vm-runtime with Apache License 2.0 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  resp.setContentType("text/plain");
  if (req.getParameter("printLogs") != null) {
    LogService ls = LogServiceFactory.getLogService();
    LogQuery query = withIncludeAppLogs(true).minLogLevel(LogService.LogLevel.FATAL);
    for (RequestLogs logs : ls.fetch(query)) {
      for (AppLogLine logLine : logs.getAppLogLines()) {
        if (logLine.getLogLevel().equals(LogService.LogLevel.FATAL)) {
          resp.getWriter().println(logLine);
        }
      }
    }
  } else {
    Logger logger = Logger.getLogger("com.foo");
    resp.getWriter().println(logger.getLevel());
    Logger logger2 = Logger.getLogger("com.foo.bar");
    resp.getWriter().println(logger2.getLevel());
    resp.getWriter().println(configRan);
    logger2.severe("not null");
    logger2.severe((String)null);
  }
}
 
Example 5
Source File: TestIsLoggable.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void loglevel(Level l, Logger logger, String message) {
    LogTest test = LogTest.valueOf("LEV_"+l.getName());
    switch(test) {
        case LEV_SEVERE:
            logger.severe(message);
            break;
        case LEV_WARNING:
            logger.warning(message);
            break;
        case LEV_INFO:
            logger.info(message);
            break;
        case LEV_CONFIG:
            logger.config(message);
            break;
        case LEV_FINE:
            logger.fine(message);
            break;
        case LEV_FINER:
            logger.finer(message);
            break;
        case LEV_FINEST:
            logger.finest(message);
            break;
    }
}
 
Example 6
Source File: SnapshotCommand.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
    try (GridClient client = Command.startClient(clientCfg)) {
        return executeTaskByNameOnNode(
            client,
            taskName,
            taskArgs,
            null,
            clientCfg
        );
    }
    catch (Throwable e) {
        log.severe("Failed to perform operation.");
        log.severe(CommandLogger.errorMessage(e));

        throw e;
    }
}
 
Example 7
Source File: EncryptionCommand.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public Object execute(GridClientConfiguration clientCfg, Logger logger) throws Exception {
    try (GridClient client = Command.startClient(clientCfg)) {
        return executeTaskByNameOnNode(
            client,
            taskName,
            taskArgs,
            null,
            clientCfg
        );
    }
    catch (Throwable e) {
        logger.severe("Failed to perform operation.");
        logger.severe(CommandLogger.errorMessage(e));

        throw e;
    }
}
 
Example 8
Source File: ActivateCommand.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Activate cluster.
 *
 * @param cfg Client configuration.
 * @throws GridClientException If failed to activate.
 */
@Override public Object execute(GridClientConfiguration cfg, Logger logger) throws Exception {
    logger.warning("Command deprecated. Use " + SET_STATE.toString() + " instead.");

    try (GridClient client = Command.startClient(cfg)) {
        GridClientClusterState state = client.state();

        state.state(ACTIVE, false);

        logger.info("Cluster activated");
    }
    catch (Throwable e) {
        logger.severe("Failed to activate cluster.");

        throw e;
    }

    return null;
}
 
Example 9
Source File: TestIsLoggable.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void loglevel(Level l, Logger logger, String message) {
    LogTest test = LogTest.valueOf("LEV_"+l.getName());
    switch(test) {
        case LEV_SEVERE:
            logger.severe(message);
            break;
        case LEV_WARNING:
            logger.warning(message);
            break;
        case LEV_INFO:
            logger.info(message);
            break;
        case LEV_CONFIG:
            logger.config(message);
            break;
        case LEV_FINE:
            logger.fine(message);
            break;
        case LEV_FINER:
            logger.finer(message);
            break;
        case LEV_FINEST:
            logger.finest(message);
            break;
    }
}
 
Example 10
Source File: ExecutorUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Await termination of the given {@link ExecutorService}. If it does not terminate within the
 * given time, log a severe error to the given logger, mentioning that the given technique was
 * used to try and shut it down.
 *
 * @return true if the executor terminated in time, false if it timed out
 */
public static boolean awaitTermination(ExecutorService service, Logger logger, Duration timeout, String technique) {
    try {
        service.awaitTermination(timeout.toMillis(), TimeUnit.MILLISECONDS);
        return true;
    } catch(InterruptedException e) {
        logger.severe(technique + " shutdown of " + service + " did not complete within " + timeout);
        return false;
    }
}
 
Example 11
Source File: BaselineCommand.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Change baseline.
 *
 * @param clientCfg Client configuration.
 * @throws Exception If failed to execute baseline action.
 */
@Override public Object execute(GridClientConfiguration clientCfg, Logger logger) throws Exception {
    try (GridClient client = Command.startClient(clientCfg)) {
        UUID coordinatorId = client.compute()
            //Only non client node can be coordinator.
            .nodes(node -> !node.isClient())
            .stream()
            .min(Comparator.comparingLong(GridClientNode::order))
            .map(GridClientNode::nodeId)
            .orElse(null);

        VisorBaselineTaskResult res = executeTaskByNameOnNode(
            client,
            VisorBaselineTask.class.getName(),
            toVisorArguments(baselineArgs),
            coordinatorId,
            clientCfg
        );

        baselinePrint0(res, logger);
    }
    catch (Throwable e) {
        logger.severe("Failed to execute baseline command='" + baselineArgs.getCmd().text() + "'");
        logger.severe(CommandLogger.errorMessage(e));

        throw e;
    }

    return null;
}
 
Example 12
Source File: StateCommand.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Print cluster state.
 *
 * @param clientCfg Client configuration.
 * @throws Exception If failed to print state.
 */
@Override public Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
    try (GridClient client = Command.startClient(clientCfg)) {
        GridClientClusterState state = client.state();

        ClusterState clusterState = state.state();

        switch (clusterState) {
            case ACTIVE:
                log.info("Cluster is active");

                break;

            case INACTIVE:
                log.info("Cluster is inactive");

                break;

            case ACTIVE_READ_ONLY:
                log.info("Cluster is active (read-only)");

                break;

            default:
                throw new IllegalStateException("Unknown state: " + clusterState);
        }
    }
    catch (Throwable e) {
        if (!CommandHandler.isAuthError(e))
            log.severe("Failed to get cluster state.");

        throw e;
    }

    return null;
}
 
Example 13
Source File: ApiServer.java    From lancoder with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void stop() {
	super.stop();
	try {
		server.stop();
	} catch (Exception e) {
		Logger logger = Logger.getLogger("lancoder");
		logger.severe(e.getMessage());
	}
}
 
Example 14
Source File: CallerInformationTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testClassLogger() throws Exception {
    final ListAppender app = ctx.getListAppender("Class").clear();
    final Logger logger = Logger.getLogger("ClassLogger");
    logger.info("Ignored message contents.");
    logger.warning("Verifying the caller class is still correct.");
    logger.severe("Hopefully nobody breaks me!");
    final List<String> messages = app.getMessages();
    assertEquals("Incorrect number of messages.", 3, messages.size());
    for (final String message : messages) {
        assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
    }
}
 
Example 15
Source File: UUIDConversion.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    Logger logger = PlayerVaults.getInstance().getLogger();

    File newDir = PlayerVaults.getInstance().getVaultData();
    if (newDir.exists()) {
        return;
    }

    File oldVaults = new File(PlayerVaults.getInstance().getDataFolder() + File.separator + "vaults");
    if (oldVaults.exists()) {
        logger.info("********** Starting conversion to UUIDs for PlayerVaults **********");
        logger.info("This might take awhile.");
        logger.info(oldVaults.toString() + " will remain as a backup.");

        for (File file : oldVaults.listFiles()) {
            if (file.isDirectory()) {
                continue; // backups folder.
            }
            OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().replace(".yml", ""));
            if (player == null) {
                logger.warning("Unable to convert file because player never joined the server: " + file.getName());
                break;
            }

            File newFile = new File(PlayerVaults.getInstance().getVaultData(), player.getUniqueId().toString() + ".yml");
            file.mkdirs();
            try {
                Files.copy(file, newFile);
                logger.info("Successfully converted vault file for " + player.getName());
            } catch (IOException e) {
                logger.severe("Couldn't convert vault file for " + player.getName());
            }
        }

        logger.info("********** Conversion done ;D **********");
    }
}
 
Example 16
Source File: UserDataHelper.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Configures the agent from a IaaS registry.
 * @param logger a logger
 * @return the agent's data, or null if they could not be parsed
 */
public AgentProperties findParametersForAmazonOrOpenStack( Logger logger ) {
	logger.info( "User data are being retrieved for AWS / Openstack..." );

	// Copy the user data
	String userData = Utils.readUrlContentQuietly( "http://169.254.169.254/latest/user-data", logger );
	String ip = Utils.readUrlContentQuietly( "http://169.254.169.254/latest/meta-data/public-ipv4", logger );

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

		// Verify the IP
		if( ! AgentUtils.isValidIP( ip )) {
			// Failed retrieving public IP: try private one instead
			ip = Utils.readUrlContentQuietly( "http://169.254.169.254/latest/meta-data/local-ipv4", logger );
		}

		if( AgentUtils.isValidIP( ip ))
			result.setIpAddress( ip );
		else
			logger.severe( "No IP address could be retrieved (either public-ipv4 or local-ipv4)." );

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

	return result;
}
 
Example 17
Source File: PacketLinkExHost.java    From SubServers-2 with Apache License 2.0 5 votes vote down vote up
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) throws Throwable {
    Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.getConnection()), null);
    if (data.getInt(0x0001) == 0) {
        setReady(client.getConnection(), true);
    } else {
        log.severe("Could not link name with host" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
        DebugUtil.logException(new IllegalStateException(), log);
        GalaxiEngine.getInstance().stop();
    }
}
 
Example 18
Source File: MemorySettingsTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void test() {
    final Runtime runtime = Runtime.getRuntime();

    System.out.println("maxMemory = " + runtime.maxMemory());

    System.out.println("freeMemory = " + runtime.freeMemory());

    System.out.println("totalMemory = " + runtime.totalMemory());

    final Logger logger = Logger.getLogger(MemorySettingsTest.class.getName());

    logger.severe("maxMemory = " + runtime.maxMemory());

    logger.severe("freeMemory = " + runtime.freeMemory());

    logger.severe("totalMemory = " + runtime.totalMemory());
}
 
Example 19
Source File: VmApiProxyDelegate.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
/**
 * Convert the RemoteApiPb.RpcError to the appropriate exception.
 *
 * @param rpcError the RemoteApiPb.RpcError.
 * @param packageName the name of the API package.
 * @param methodName the name of the method within the API package.
 * @param logger the Logger used to create log messages.
 * @return ApiProxyException
 */
private static ApiProxyException convertApiResponseRpcErrorToException(
    RemoteApiPb.RpcError rpcError, String packageName, String methodName, Logger logger) {

  int rpcCode = rpcError.getCode();
  String errorDetail = rpcError.getDetail();
  if (rpcCode > RemoteApiPb.RpcError.ErrorCode.values().length) {
    logger.severe("Received unrecognized error code from server: " + rpcError.getCode() +
        " details: " + errorDetail);
    return new ApiProxy.UnknownException(packageName, methodName);
  }
  RemoteApiPb.RpcError.ErrorCode errorCode = RemoteApiPb.RpcError.ErrorCode.values()[
      rpcError.getCode()];
  logger.warning("RPC failed, API=" + packageName + "." + methodName + " : "
                 + errorCode + " : " + errorDetail);

  // This is very similar to apphosting/utils/runtime/ApiProxyUtils.java#convertApiError,
  // which is for APIResponse. TODO(user): retire both in favor of gRPC.
  switch (errorCode) {
    case CALL_NOT_FOUND:
      return new ApiProxy.CallNotFoundException(packageName, methodName);
    case PARSE_ERROR:
      return new ApiProxy.ArgumentException(packageName, methodName);
    case SECURITY_VIOLATION:
      logger.severe("Security violation: invalid request id used!");
      return new ApiProxy.UnknownException(packageName, methodName);
    case CAPABILITY_DISABLED:
      return new ApiProxy.CapabilityDisabledException(
          errorDetail, packageName, methodName);
    case OVER_QUOTA:
      return new ApiProxy.OverQuotaException(packageName, methodName);
    case REQUEST_TOO_LARGE:
      return new ApiProxy.RequestTooLargeException(packageName, methodName);
    case RESPONSE_TOO_LARGE:
      return new ApiProxy.ResponseTooLargeException(packageName, methodName);
    case BAD_REQUEST:
      return new ApiProxy.ArgumentException(packageName, methodName);
    case CANCELLED:
      return new ApiProxy.CancelledException(packageName, methodName);
    case FEATURE_DISABLED:
      return new ApiProxy.FeatureNotEnabledException(
          errorDetail, packageName, methodName);
    case DEADLINE_EXCEEDED:
      return new ApiProxy.ApiDeadlineExceededException(packageName, methodName);
    default:
      return new ApiProxy.UnknownException(packageName, methodName);
  }
}
 
Example 20
Source File: LogController.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@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();
}