Java 8 XMLFormatter - 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 XMLFormatter class.

This code example shows how to use the following methods:getHead, getTail
    } 
 
    public void testXMLFormatter() throws SecurityException, UnsupportedEncodingException { 
        handler.setEncoding("UTF-8");
 
        String result = formatter.getHead(handler);
        int headPos = result
                .indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
        int dtdPos = result.indexOf("<!DOCTYPE log SYSTEM \"logger.dtd\">");
        int rootPos = result.indexOf("<log>");
        assertTrue("head string position should be more or equal zero",
                headPos >= 0);
        assertTrue("dtd string position should be more head string position",
                dtdPos > headPos);
        assertTrue("root string position should be more dtd string position",
                rootPos > dtdPos);
 
        assertTrue("Tail string position should be more zero", formatter
                .getTail(handler).indexOf("/log>") > 0);
    } 

6
CodeRank
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
This code example shows how to use the following methods:setFormatter, setLevel
        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);
        } catch (final IOException e) {
            ErlLogger.error(e);
        } 
    } 
 
    private static StackTraceElement getCaller() {
        final StackTraceElement[] st = new Throwable().getStackTrace();
        StackTraceElement el = null;
        int i = 2;
7
CodeRank
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
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
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
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
This code example shows how to use the following methods:getEncoding, getFilter, getFormatter, getLevel, close
		// start the server to be ready to accept log messages 
		ServerThread thread = new ServerThread();
		thread.start();
		Thread.sleep(2000);
 
		h = new SocketHandler();
		assertSame(h.getLevel(), Level.ALL);
		assertTrue(h.getFormatter() instanceof XMLFormatter);
		assertNull(h.getFilter());
		assertNull(h.getEncoding());
		h.close();
		// ensure the thread exits and the port becomes available again 
		thread.getReadString();
 
		try { 
			h = new SocketHandler("127.0.sdfcdsfsa%%&&^0.1", 6665);
			fail("Should throw IOException!");
		} catch (IOException e) {
		} 
	} 
6
CodeRank
This code example shows how to use the following methods:setFormatter
 
  static { 
    String LOGGER_NAME = "AnotherRunnerLogger";
    logger = Logger.getLogger(LOGGER_NAME);
    try { 
      FileHandler fileHandler = new FileHandler(LOGGER_NAME + ".log");
      fileHandler.setFormatter(new SimpleFormatter());
      logger.addHandler(fileHandler);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } 
  } 
 
  public FeelingDifferentRunner(Class<?> klass) throws InitializationError {
    super(klass);
  } 
 
  @Override 
  protected Statement methodBlock(FrameworkMethod method) {
    logger.severe(method.toString());
6
CodeRank
This code example shows how to use the following methods:setFormatter, setLevel
        logger.addHandler(consoleHandler);
    } 
 
    private void addFileHandler(final ErlSimpleFormatter formatter) {
        try { 
            fileHandler = new FileHandler(getLogLocation());
            fileHandler.setFormatter(formatter);
            fileHandler.setLevel(java.util.logging.Level.FINEST);
            logger.addHandler(fileHandler);
        } catch (final SecurityException e) {
            ErlLogger.error(e);
        } catch (final IOException e) {
            ErlLogger.error(e);
        } 
    } 
 
    private static StackTraceElement getCaller() {
        final StackTraceElement[] st = new Throwable().getStackTrace();
        StackTraceElement el = null;
        int i = 2;
6
CodeRank
See Code Examples for Java 8 XMLFormatter Methods: