Example usage for java.util.logging Logger getParent

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

Introduction

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

Prototype

public Logger getParent() 

Source Link

Document

Return the parent for this Logger.

Usage

From source file:org.wattdepot.server.WattDepotServer.java

/**
 * Creates a new instance of the WattDepot server.
 * /*www . j a v  a 2s.co  m*/
 * @param properties
 *          The ServerProperties used to initialize this server.
 * @return The WattDepotServer.
 * @throws Exception
 *           if there is a problem starting the server.
 */
public static WattDepotServer newInstance(ServerProperties properties) throws Exception {
    int port = Integer.parseInt(properties.get(ServerProperties.PORT_KEY));
    WattDepotServer server = new WattDepotServer();
    // System.out.println("WattDepotServer.");
    //    LoggerUtil.showLoggers();
    boolean enableLogging = Boolean.parseBoolean(properties.get(ServerProperties.ENABLE_LOGGING_KEY));
    server.serverProperties = properties;
    server.hostName = server.serverProperties.getFullHost();

    // Get the WattDepotPersistence implementation.
    String depotClass = properties.get(ServerProperties.WATT_DEPOT_IMPL_KEY);
    server.depot = (WattDepotPersistence) Class.forName(depotClass).getConstructor(ServerProperties.class)
            .newInstance(properties);
    if (server.depot.getSessionOpen() != server.depot.getSessionClose()) {
        throw new RuntimeException("opens and closed mismatched.");
    }
    server.depot.initializeMeasurementTypes();
    if (server.depot.getSessionOpen() != server.depot.getSessionClose()) {
        throw new RuntimeException("opens and closed mismatched.");
    }
    server.depot.initializeSensorModels();
    if (server.depot.getSessionOpen() != server.depot.getSessionClose()) {
        throw new RuntimeException("opens and closed mismatched.");
    }
    server.depot.setServerProperties(properties);
    server.restletServer = new WattDepotComponent(server.depot, port);
    server.logger = server.restletServer.getLogger();

    // Set up logging.
    if (enableLogging) {
        LoggerUtil.useConsoleHandler();
        Logger base = LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME);
        base = base.getParent();
        String level = properties.get(ServerProperties.LOGGING_LEVEL_KEY);
        LoggerUtil.setLoggingLevel(base, level);

        server.logger.info("Starting WattDepot server.");
        server.logger.info("Host: " + server.hostName);
        server.logger.info(server.serverProperties.echoProperties());
    } else {
        LoggerUtil.useConsoleHandler();
        Logger base = LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME);
        base = base.getParent();
        LoggerUtil.setLoggingLevel(base, Level.SEVERE.toString());
    }
    server.restletServer.start();

    server.logger.info("WattDepot server now running.");

    //    LoggerUtil.showLoggers();
    return server;
}

From source file:shuffle.fwk.ShuffleController.java

/**
 * The main which starts the program.//ww  w  . jav a2  s .c  o  m
 * 
 * @param args
 *           unused.
 */
public static void main(String... args) {
    String userHomeArg = null;
    String levelToSetArg = null;

    if (args != null && args.length > 0) {
        userHomeArg = args[0];
        if (args.length > 1) {
            levelToSetArg = args[1];
        }
    }

    if (userHomeArg == null) {
        userHomeArg = System.getProperty("user.home") + File.separator + "Shuffle-Move";
    }
    setUserHome(userHomeArg);
    try {
        FileHandler handler = new FileHandler();
        Logger toRoot = LOG;
        while (toRoot.getParent() != null) {
            toRoot = toRoot.getParent();
        }
        toRoot.addHandler(handler);
    } catch (SecurityException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    if (levelToSetArg != null) {
        try {
            Level levelToSet = Level.parse(args[1]);
            Logger.getLogger(SimulationTask.class.getName()).setLevel(levelToSet);
            SimulationTask.setLogFiner(levelToSet.intValue() <= Level.FINER.intValue());
            Logger.getLogger(ShuffleModel.class.getName()).setLevel(levelToSet);
        } catch (Exception e) {
            LOG.fine("Cannot set simulation logging to that level: " + StringUtils.join(args));
        }
    }

    ShuffleController ctrl = new ShuffleController();
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            ctrl.getFrame().launch();
        }
    });
}

From source file:tiemens.util.instancer.antlr.InstancerCode.java

/**
 * If loggingConfigureString is NOT UPPER CASE,
 * Then/*from w w  w .ja  v  a2  s .  c  o  m*/
 *    If uselogger's handler(s) are examined and changed if they
 *       would not log at 'newLevel'
 * 
 * @param newLevel the parsed loggingConfigureString
 * @param uselogger whose handler(s) we change
 * @param loggingConfigureString original configuration string
 */
private void updateHandlers(Level newLevel, Logger uselogger, String loggingConfigureString) {
    List<Handler> handlers = new ArrayList<Handler>();
    Logger walk = uselogger;
    while (walk != null) {
        for (Handler add : walk.getHandlers()) {
            handlers.add(add);
        }
        walk = walk.getParent();
    }

    for (Handler handler : handlers) {
        metaLoggerInfo(
                "Handler level = " + handler.getLevel().intValue() + "newLevel = " + newLevel.intValue());

        if (handler.getLevel().intValue() > newLevel.intValue()) {
            if (!loggingConfigureString.equals(loggingConfigureString.toUpperCase())) {
                String note = "Note: setting handler level to '" + loggingConfigureString + "'.";
                String explain = "Use '" + loggingConfigureString.toUpperCase() + "' to prevent this behavior.";
                String msg = "Instancer: " + note + "  " + explain;
                metaLoggerInfo(msg);
                logger.info(msg);
                handler.setLevel(newLevel);
            }
        }
    }
}