List of usage examples for java.util.logging Logger removeHandler
public void removeHandler(Handler handler) throws SecurityException
From source file:com.googlecode.promnetpp.main.Main.java
/** * Main function (entry point for the tool). * * @param args Command-line arguments./* www . j a va2 s. c om*/ */ public static void main(String[] args) { //Prepare logging try { Handler fileHandler = new FileHandler("promnetpp-log.xml"); Logger logger = Logger.getLogger(""); logger.removeHandler(logger.getHandlers()[0]); logger.addHandler(fileHandler); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } String PROMNeTppHome = System.getenv("PROMNETPP_HOME"); if (PROMNeTppHome == null) { String userDir = System.getProperty("user.dir"); System.err.println("WARNING: PROMNETPP_HOME environment variable" + " not set."); System.err.println("PROMNeT++ will assume " + userDir + " as" + " home."); PROMNeTppHome = userDir; } System.setProperty("promnetpp.home", PROMNeTppHome); Logger.getLogger(Main.class.getName()).log(Level.INFO, "PROMNeT++ home" + " set to {0}", System.getProperty("promnetpp.home")); if (args.length == 1) { fileNameOrPath = args[0]; configurationFilePath = PROMNeTppHome + "/default-configuration.xml"; } else if (args.length == 2) { fileNameOrPath = args[0]; configurationFilePath = args[1]; } else { System.err.println("Invalid number of command-line arguments."); System.err.println("Usage #1: promnetpp.jar <PROMELA model>.pml"); System.err.println("Usage #2: promnetpp.jar <PROMELA model>.pml" + " <configuration file>.xml"); System.exit(1); } //We must have a file name or path at this point assert fileNameOrPath != null : "Unspecified file name or" + " path to file!"; //Log basic info Logger.getLogger(Main.class.getName()).log(Level.INFO, "Running" + " PROMNeT++ from {0}", System.getProperty("user.dir")); //Final steps loadXMLFile(); Verifier verifier = new StandardVerifier(fileNameOrPath); verifier.doVerification(); assert verifier.isErrorFree() : "Errors reported during model" + " verification!"; verifier.finish(); buildAbstractSyntaxTree(); Translator translator = new StandardTranslator(); translator.init(); translator.translate(abstractSyntaxTree); translator.finish(); }
From source file:org.azrul.langmera.DecisionService.java
public static void main(String[] args) throws IOException { ConfigurationProvider config = null; ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("config.properties")); if (args.length <= 0) { ConfigurationSource source = new ClasspathConfigurationSource(configFilesProvider); config = new ConfigurationProviderBuilder().withConfigurationSource(source).build(); } else {//from w ww . j a va 2 s . c o m ConfigurationSource source = new FilesConfigurationSource(configFilesProvider); Environment environment = new ImmutableEnvironment(args[0]); config = new ConfigurationProviderBuilder().withConfigurationSource(source).withEnvironment(environment) .build(); } Logger logger = null; if (config.getProperty("log.file", String.class).isEmpty() == false) { FileHandler logHandler = new FileHandler(config.getProperty("log.file", String.class), config.getProperty("log.sizePerFile", Integer.class) * 1024 * 1024, config.getProperty("log.maxFileCount", Integer.class), true); logHandler.setFormatter(new SimpleFormatter()); logHandler.setLevel(Level.INFO); Logger rootLogger = Logger.getLogger(""); rootLogger.removeHandler(rootLogger.getHandlers()[0]); logHandler.setLevel(Level.parse(config.getProperty("log.level", String.class))); rootLogger.setLevel(Level.parse(config.getProperty("log.level", String.class))); rootLogger.addHandler(logHandler); logger = rootLogger; } else { logger = Logger.getGlobal(); } VertxOptions options = new VertxOptions(); options.setMaxEventLoopExecuteTime(Long.MAX_VALUE); options.setWorkerPoolSize(config.getProperty("workerPoolSize", Integer.class)); options.setEventLoopPoolSize(40); Vertx vertx = Vertx.vertx(options); vertx.deployVerticle(new DecisionService(logger, config)); vertx.deployVerticle(new SaveToDB(logger, config)); }
From source file:de.pniehus.odal.App.java
public static void main(String[] args) throws IOException { List<Filter> filters = new ArrayList<Filter>(); filters.add(new RegexFilter()); filters.add(new FileTypeFilter()); filters.add(new KeywordFilter()); filters.add(new BlacklistFilter()); Profile p = parseArgs(args, filters); String fileName = "log-" + new Date().toString().replace(":", "-") + ".txt"; fileName = fileName.replace(" ", "-"); File logPath = new File(p.getLogDirectory() + fileName); if (!logPath.getParentFile().isDirectory() && !logPath.getParentFile().mkdirs()) { logPath = new File(fileName); }//from ww w.j a v a 2 s. c o m if (logPath.getParentFile().canWrite() || logPath.getParentFile().setWritable(true)) { SimpleLoggingSetup.configureRootLogger(logPath.getAbsolutePath(), p.getLogLevel(), !p.isSilent()); } else { Logger root = Logger.getLogger(""); for (Handler h : root.getHandlers()) { // Removing default console handlers if (h instanceof ConsoleHandler) { root.removeHandler(h); } } ConsolePrintLogHandler cplh = new ConsolePrintLogHandler(); cplh.setFormatter(new ScribblerLogFormat(SimpleLoggingSetup.DEFAULT_DATE_FORMAT)); root.addHandler(cplh); System.out.println("Unable to create log: insufficient permissions!"); } Logger.getLogger("").setLevel(p.getLogLevel()); mainLogger = Logger.getLogger(App.class.getCanonicalName()); untrustedSSLSetup(); mainLogger.info("Successfully intitialized ODAL"); if (!p.isLogging()) mainLogger.setLevel(Level.OFF); if (p.isWindowsConsoleMode() && !p.isLogging()) { Logger root = Logger.getLogger(""); for (Handler h : root.getHandlers()) { if (h instanceof FileHandler) { root.removeHandler(h); // Removes FileHandler to allow console output through logging } } } OdalGui ogui = new OdalGui(p, filters); }
From source file:net.sf.freecol.FreeCol.java
/** * The entrypoint.//w ww. ja va 2 s.com * * @param args The command-line arguments. * @throws IOException * @throws FontFormatException */ public static void main(String[] args) throws FontFormatException, IOException { freeColRevision = FREECOL_VERSION; JarURLConnection juc; try { juc = getJarURLConnection(FreeCol.class); } catch (IOException ioe) { juc = null; System.err.println("Unable to open class jar: " + ioe.getMessage()); } if (juc != null) { try { String revision = readVersion(juc); if (revision != null) { freeColRevision += " (Revision: " + revision + ")"; } } catch (Exception e) { System.err.println("Unable to load Manifest: " + e.getMessage()); } try { splashStream = getDefaultSplashStream(juc); } catch (Exception e) { System.err.println("Unable to open default splash: " + e.getMessage()); } } // Java bug #7075600 causes BR#2554. The workaround is to set // the following property. Remove if/when they fix Java. System.setProperty("java.util.Arrays.useLegacyMergeSort", "true"); // We can not even emit localized error messages until we find // the data directory, which might have been specified on the // command line. String dataDirectoryArg = findArg("--freecol-data", args); String err = FreeColDirectories.setDataDirectory(dataDirectoryArg); if (err != null) fatal(err); // This must not fail. // Now we have the data directory, establish the base locale. // Beware, the locale may change! String localeArg = findArg("--default-locale", args); if (localeArg == null) { locale = Locale.getDefault(); } else { int index = localeArg.indexOf('.'); // Strip encoding if present if (index > 0) localeArg = localeArg.substring(0, index); locale = Messages.getLocale(localeArg); } Messages.loadMessageBundle(locale); // Now that we can emit error messages, parse the other // command line arguments. handleArgs(args); // Do the potentially fatal system checks as early as possible. if (javaCheck && JAVA_VERSION_MIN.compareTo(JAVA_VERSION) > 0) { fatal(StringTemplate.template("main.javaVersion").addName("%version%", JAVA_VERSION) .addName("%minVersion%", JAVA_VERSION_MIN)); } if (memoryCheck && MEMORY_MAX < MEMORY_MIN * 1000000) { fatal(StringTemplate.template("main.memory").addAmount("%memory%", MEMORY_MAX).addAmount("%minMemory%", MEMORY_MIN)); } // Having parsed the command line args, we know where the user // directories should be, so we can set up the rest of the // file/directory structure. String userMsg = FreeColDirectories.setUserDirectories(); // Now we have the log file path, start logging. final Logger baseLogger = Logger.getLogger(""); final Handler[] handlers = baseLogger.getHandlers(); for (Handler handler : handlers) { baseLogger.removeHandler(handler); } String logFile = FreeColDirectories.getLogFilePath(); try { baseLogger.addHandler(new DefaultHandler(consoleLogging, logFile)); Logger freecolLogger = Logger.getLogger("net.sf.freecol"); freecolLogger.setLevel(logLevel); } catch (FreeColException e) { System.err.println("Logging initialization failure: " + e.getMessage()); e.printStackTrace(); } Thread.setDefaultUncaughtExceptionHandler((Thread thread, Throwable e) -> { baseLogger.log(Level.WARNING, "Uncaught exception from thread: " + thread, e); }); // Now we can find the client options, allow the options // setting to override the locale, if no command line option // had been specified. // We have users whose machines default to Finnish but play // FreeCol in English. // If the user has selected automatic language selection, do // nothing, since we have already set up the default locale. if (localeArg == null) { String clientLanguage = ClientOptions.getLanguageOption(); Locale clientLocale; if (clientLanguage != null && !Messages.AUTOMATIC.equalsIgnoreCase(clientLanguage) && (clientLocale = Messages.getLocale(clientLanguage)) != locale) { locale = clientLocale; Messages.loadMessageBundle(locale); logger.info("Loaded messages for " + locale); } } // Now we have the user mods directory and the locale is now // stable, load the mods and their messages. Mods.loadMods(); Messages.loadModMessageBundle(locale); // Report on where we are. if (userMsg != null) logger.info(Messages.message(userMsg)); logger.info(getConfiguration().toString()); // Ready to specialize into client or server. if (standAloneServer) { startServer(); } else { startClient(userMsg); } startYourAddition(); }
From source file:org.stanwood.nwn2.gui.logging.JavaLoggingToCommonLoggingRedirector.java
/** * Deactivates this feature./*from w ww . ja v a 2 s .co m*/ */ public static void deactivate() { Logger rootLogger = LogManager.getLogManager().getLogger(""); rootLogger.removeHandler(activeHandler); Logger.getLogger(JavaLoggingToCommonLoggingRedirector.class.getName()).info("dactivated"); }
From source file:jshm.logging.Log.java
public static Logger removeHandlers(final Logger logger) { for (Handler h : logger.getHandlers()) logger.removeHandler(h); return logger; }
From source file:org.eclipse.ecr.common.logging.JavaUtilLoggingHelper.java
/** * Resets {@code java.util.logging} redirections. *//*w ww . j a v a 2 s. co m*/ public static synchronized void reset() { if (activeHandler == null) { return; } try { Logger rootLogger = LogManager.getLogManager().getLogger(""); rootLogger.removeHandler(activeHandler); } catch (Exception e) { log.error("Handler removal failed", e); } activeHandler = null; }
From source file:org.nuxeo.common.logging.JavaUtilLoggingHelper.java
/** * Resets {@code java.util.logging} redirections. *//*from ww w .j a v a 2 s .co m*/ public static synchronized void reset() { if (activeHandler == null) { return; } try { Logger rootLogger = LogManager.getLogManager().getLogger(""); rootLogger.removeHandler(activeHandler); } catch (SecurityException e) { log.error("Handler removal failed", e); } activeHandler = null; }
From source file:org.openqa.selenium.server.log.LoggingManager.java
protected static void restoreOriginalHandlersFormattersAndLevels(Logger logger) { for (Handler handler : logger.getHandlers()) { logger.removeHandler(handler); }//from w ww . j a v a 2 s .co m for (Handler handler : originalHandlers) { logger.addHandler(handler); // jbevan: java.util.logging.RestishHandler.setFormatter(null) throws an NPE if (originalFormatters.get(handler) != null) { handler.setFormatter(originalFormatters.get(handler)); } handler.setLevel(originalLogLevels.get(handler)); } }
From source file:org.stanwood.nwn2.gui.logging.JavaLoggingToCommonLoggingRedirector.java
/** * Activates this feature.// w w w . ja va2 s . c o m */ public static void activate() { try { Logger rootLogger = LogManager.getLogManager().getLogger(""); // remove old handlers for (Handler handler : rootLogger.getHandlers()) { rootLogger.removeHandler(handler); } // add our own activeHandler = new JDKLogHandler(); activeHandler.setLevel(Level.ALL); rootLogger.addHandler(activeHandler); rootLogger.setLevel(Level.ALL); } catch (Exception exc) { LogFactory.getLog(JavaLoggingToCommonLoggingRedirector.class).error("activation failed", exc); } }