Java 8 Handler - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Handler class.

This code example shows how to use the following methods:setFormatter, setLevel
      logFile = options.getLogOutFile();
      fileHandler = seleniumFileHandlers.get(logFile);
      if (fileHandler == null) {
        fileHandler = registerNewSeleniumFileHandler(logFile);
      } 
      fileHandler.setFormatter(new TerseFormatter(true));
      currentLogger.setLevel(Level.FINE);
      fileHandler.setLevel(Level.FINE);
      currentLogger.addHandler(fileHandler);
      return logFile;
    } catch (IOException e) {
      throw new RuntimeException(e);
    } 
  } 
 
  private static FileHandler registerNewSeleniumFileHandler(File logFile) throws IOException {
    FileHandler fileHandler;
    fileHandler = new FileHandler(logFile.getAbsolutePath());
    seleniumFileHandlers.put(logFile, fileHandler);
    return fileHandler;

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setFormatter, setLevel
        logger.setUseParentHandlers(false);
        logger.setLevel(java.util.logging.Level.FINEST);
    } 
 
    private void addConsoleHandler(final ErlSimpleFormatter erlSimpleFormatter) {
        consoleHandler = new ConsoleHandler();
        consoleHandler.setFormatter(erlSimpleFormatter);
        final Level lvl = java.util.logging.Level.FINEST;
        consoleHandler.setLevel(lvl);
        logger.addHandler(consoleHandler);
    } 
 
    private void addFileHandler(final ErlSimpleFormatter erlSimpleFormatter) {
        try { 
            fileHandler = new FileHandler(getLogLocation());
            fileHandler.setFormatter(erlSimpleFormatter);
            fileHandler.setLevel(java.util.logging.Level.FINEST);
            logger.addHandler(fileHandler);
        } catch (final SecurityException e) {
            ErlLogger.error(e);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setFormatter, setLevel
    { 
        ConsoleLogThread.wrappedHandler.setLevel(Level.parse(System.getProperty("fml.log.level","INFO")));
        // Console handler captures the normal stderr before it gets replaced 
        log.myLog.addHandler(new ConsoleLogWrapper());
        ConsoleLogThread.wrappedHandler.setFormatter(formatter);
        fileHandler.setLevel(Level.ALL);
        fileHandler.setFormatter(formatter);
        log.myLog.addHandler(fileHandler);
    } 
 
    public static void loadLogConfiguration(File logConfigFile)
    { 
        if (logConfigFile!=null && logConfigFile.exists() && logConfigFile.canRead())
        { 
            try 
            { 
                LogManager.getLogManager().readConfiguration(new FileInputStream(logConfigFile));
                resetLoggingHandlers(); 
            } 
            catch (Exception e)
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setFormatter
        String logfile = getProperty("util.logfile");
        if ( logdir != null ) {
            try { 
                Logger logger = Logger.getLogger("prefuse");
                logger.setUseParentHandlers(false);
                Handler fileHandler = new FileHandler(logdir+"/"+logfile);
                fileHandler.setFormatter(new SimpleFormatter());
                logger.addHandler(fileHandler);
            } catch ( IOException e ) {
                e.printStackTrace();
            } 
        } 
    } 
     
    /** 
     * Get a prefuse configuration property. 
     * @param key the name of the property to lookup 
     * @return the property value, or null if the key is not found 
     */ 
    public static String get(String key) {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setFormatter
        this.bungee = bungee;
        this.writer = new ColouredWriter( bungee.getConsoleReader() );
 
        try 
        { 
            FileHandler handler = new FileHandler( "proxy.log", 1 << 24, 8, true );
            handler.setFormatter( formatter );
            addHandler( handler );
        } catch ( IOException ex )
        { 
            System.err.println( "Could not register logger!" );
            ex.printStackTrace();
        } 
        dispatcher.start();
    } 
 
    @Override 
    public void log(LogRecord record)
    { 
        dispatcher.queue( record );
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setFormatter, setLevel
     * @param args command-line arguments 
     * @throws DatabaseException 
     * @throws IOException 
     */ 
    public static void main(String[] args) throws DatabaseException, IOException {
        Handler handler = new ConsoleHandler();
        handler.setLevel(Level.ALL);
        handler.setFormatter(new OneLineSimpleLogger());
        logger.addHandler(handler);
        logger.setUseParentHandlers(false);
 
        if (args.length == 2) {
            logger.setLevel(Level.INFO);
            populatePersistEnv(args[0], new File(args[1]));
        } else if (args.length == 1) {
            logger.setLevel(Level.FINE);
            populatePersistEnv(args[0], null);
        } else { 
            System.out.println("Arguments: ");
            System.out.println("    source [target]");
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setFormatter
 
		// Get the global logger to configure it 
		Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
 
		logger.setLevel(Level.INFO);
		fileTxt = new FileHandler("Logging.txt");
		fileHTML = new FileHandler("Logging.html");
 
		// Create txt Formatter 
		formatterTxt = new SimpleFormatter();
		fileTxt.setFormatter(formatterTxt);
		logger.addHandler(fileTxt);
 
		// Create HTML Formatter 
		formatterHTML = new MyHtmlFormatter();
		fileHTML.setFormatter(formatterHTML);
		logger.addHandler(fileHTML);
	} 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getEncoding, getErrorManager, getFilter, getFormatter, getLevel
        assertTrue(handler.isLoggable(new LogRecord(Level.WARNING, "2")));
        assertTrue(handler.isLoggable(new LogRecord(Level.SEVERE, "3")));
    } 
 
    public void testMemoryHandler() throws IOException { 
        assertNotNull("Filter should not be null", handler.getFilter());
        assertNotNull("Formatter should not be null", handler.getFormatter());
        assertNull("character encoding should be null", handler.getEncoding());
        assertNotNull("ErrorManager should not be null", handler.getErrorManager());
        assertEquals("Level should be FINE", Level.FINE, handler.getLevel());
        assertEquals("Level should be WARNING", Level.WARNING, handler.getPushLevel());
    } 
 
    public static class MockFilter implements Filter {
        public boolean isLoggable(LogRecord record) {
            return !record.getMessage().equals("false");
        } 
    } 
 
    public static class MockHandler extends Handler {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setFilter, setFormatter, setLevel
        System.out.println("Logging to " + getLogFile().getAbsolutePath());
        logAsDefault(); 
 
        Logger logger = Logger.getLogger("");
        try { 
            FileHandler handler = new FileHandler("%t/RouteConverter.log", LOG_SIZE, 1, true);
            handler.setLevel(ALL);
            handler.setFilter(FILTER);
            handler.setFormatter(new SimpleFormatter());
            logger.addHandler(handler);
        } catch (IOException e) {
            System.err.println("Cannot configure file logging");
            e.printStackTrace();
        } 
        // using ALL brings up a colored JavaFX WebView 
        // logger.setLevel(ALL); 
        redirectStdOutAndErrToLog(); 
    } 
 
    public void logToConsole() { 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setLevel
 
	private SelectorThread threadSelector;
	private String baseUri;
 
	public TestServer(String aPackage) throws IllegalArgumentException, IOException {
		Handler h = new ConsoleHandler(); h.setLevel(Level.ALL);
		Logger.getLogger("").addHandler(h);
		 
		baseUri = "http://localhost:9998/";
		final Map<String, String> initParams = new HashMap<String, String>();
 
		initParams.put("com.sun.jersey.config.property.packages",
				aPackage);
 
		System.out.println("Starting grizzly...");
		threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams);
		System.out.println(String
				.format("Jersey app started with WADL available at %sapplication.wadl\n", baseUri));
	} 
	 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Handler Questions & Answers:

See Code Examples for Java 8 Handler Methods: