Examples of FileHandler


Examples of java.util.logging.FileHandler

                fail("should throw security exception");
            } catch (SecurityException e) {
            }

            try {
                handler = new FileHandler();
                fail("should throw security exception");
            } catch (SecurityException e) {
            }

            try {
                handler = new FileHandler("pattern1");
                fail("should throw security exception");
            } catch (SecurityException e) {
            }
            try {
                handler = new FileHandler("pattern2", true);
                fail("should throw security exception");
            } catch (SecurityException e) {
            }
            try {
                handler = new FileHandler("pattern3", 1000, 1);
                fail("should throw security exception");
            } catch (SecurityException e) {
            }
            try {
                handler = new FileHandler("pattern4", 1000, 1, true);
                fail("should throw security exception");
            } catch (SecurityException e) {
            }
        } finally {
            System.setSecurityManager(currentManager);
View Full Code Here

Examples of java.util.logging.FileHandler

        handler.close();

        manager.readConfiguration(EnvironmentHelper
                .PropertiesToInputStream(props));
        handler = new FileHandler();
        assertEquals(Level.ALL, handler.getLevel());
        assertNull(handler.getFilter());
        assertTrue(handler.getFormatter() instanceof XMLFormatter);
        assertNull(handler.getEncoding());
        handler.close();

        props.put("java.util.logging.FileHandler.pattern", "");
        manager.readConfiguration(EnvironmentHelper
                .PropertiesToInputStream(props));
        try {
            handler = new FileHandler();
            fail("shouldn't open file with empty name");
        } catch (NullPointerException e) {
        }
    }
View Full Code Here

Examples of java.util.logging.FileHandler

    }

    public void testInvalidParams() throws IOException {

        // %t and %p parsing can add file separator automatically
        FileHandler h1 = new FileHandler("%taaa");
        h1.close();
        File file = new File(TEMPPATH + SEP + "aaa");
        assertTrue(file.exists());
        reset(TEMPPATH, "aaa");

        // always parse special pattern
        try {
            h1 = new FileHandler("%t/%h");
            fail("should throw null exception");
        } catch (FileNotFoundException e) {
        }
        h1 = new FileHandler("%t%g");
        h1.close();
        file = new File(TEMPPATH + SEP + "0");
        assertTrue(file.exists());
        reset(TEMPPATH, "0");
        h1 = new FileHandler("%t%u%g");
        h1.close();
        file = new File(TEMPPATH + SEP + "00");
        assertTrue(file.exists());
        reset(TEMPPATH, "00");

        // this is normal case
        h1 = new FileHandler("%t/%u%g%%g");
        h1.close();
        file = new File(TEMPPATH + SEP + "00%g");
        assertTrue(file.exists());
        reset(TEMPPATH, "00%g");

        // multi separator has no effect
        h1 = new FileHandler("//%t//multi%g");
        h1.close();
        file = new File(TEMPPATH + SEP + "multi0");
        assertTrue(file.exists());
        reset(TEMPPATH, "multi0");

        // bad directory, IOException
        try {
            h1 = new FileHandler("%t/baddir/multi%g");
            fail("should throw IO exception");
        } catch (IOException e) {
        }
        file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0");
        assertFalse(file.exists());

        try {
            new FileHandler(null);
            fail("should throw null exception");
        } catch (NullPointerException e) {
        }
        try {
            handler.publish(null);
        } catch (NullPointerException e) {
            fail("should not throw NPE");
        }
        try {
            new FileHandler(null, false);
            fail("should throw null exception");
        } catch (NullPointerException e) {
        }
        try {
            // regression test for Harmony-1299
            new FileHandler("");
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }
        try {
            new FileHandler("%t/java%u", 0, 0);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
        }
        try {
            new FileHandler("%t/java%u", -1, 1);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
        }
    }
View Full Code Here

Examples of java.util.logging.FileHandler

     * Class under test for void FileHandler(String)
     */
    public void testFileHandlerString() throws Exception {
        // test if unique ids not specified, it will append at the end
        // no generation number is used
        FileHandler h = new FileHandler("%t/log/string");
        FileHandler h2 = new FileHandler("%t/log/string");
        FileHandler h3 = new FileHandler("%t/log/string");
        FileHandler h4 = new FileHandler("%t/log/string");
        h.publish(r);
        h2.publish(r);
        h3.publish(r);
        h4.publish(r);
        h.close();
        h2.close();
        h3.close();
        h4.close();
        assertFileContent(TEMPPATH + SEP + "log", "string", h.getFormatter(), "UTF-8");
        assertFileContent(TEMPPATH + SEP + "log", "string.1", h.getFormatter(), "UTF-8");
        assertFileContent(TEMPPATH + SEP + "log", "string.2", h.getFormatter(), "UTF-8");
        assertFileContent(TEMPPATH + SEP + "log", "string.3", h.getFormatter(), "UTF-8");

        // default is append mode
        FileHandler h6 = new FileHandler("%t/log/string%u.log");
        h6.publish(r);
        h6.close();
        FileHandler h7 = new FileHandler("%t/log/string%u.log");
        h7.publish(r);
        h7.close();
        try {
            assertFileContent(TEMPPATH + SEP + "log", "string0.log", h
                    .getFormatter(), "UTF-8");
            fail("should assertion failed");
        } catch (Error e) {
        }
        File file = new File(TEMPPATH + SEP + "log");
        assertTrue(file.list().length <= 2);

        // test unique ids
        FileHandler h8 = new FileHandler("%t/log/%ustring%u.log");
        h8.publish(r);
        FileHandler h9 = new FileHandler("%t/log/%ustring%u.log");
        h9.publish(r);
        h9.close();
        h8.close();
        assertFileContent(TEMPPATH + SEP + "log", "0string0.log", h
                .getFormatter(), "UTF-8");
        assertFileContent(TEMPPATH + SEP + "log", "1string1.log", h
                .getFormatter(), "UTF-8");
View Full Code Here

Examples of java.util.logging.FileHandler

    public void testEmptyPattern_3params() throws SecurityException,
            IOException {
        // regression HARMONY-2421
        try {
            new FileHandler(new String(), 1, 1);
            fail("Expected an IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
    }
View Full Code Here

Examples of java.util.logging.FileHandler

    public void testEmptyPattern_2params() throws SecurityException,
            IOException {
        // regression HARMONY-2421
        try {
            new FileHandler(new String(), true);
            fail("Expected an IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
    }
View Full Code Here

Examples of java.util.logging.FileHandler

    public void testEmptyPattern_4params() throws SecurityException,
            IOException {
        // regression HARMONY-2421
        try {
            new FileHandler(new String(), 1, 1, true);
            fail("Expected an IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
    }
View Full Code Here

Examples of java.util.logging.FileHandler

          try {
              logFile.getParentFile().mkdirs();
          } catch (final Exception e) {
            LogUtil.logSevere(e);
          }
          fileHandler = new FileHandler(logFile.getCanonicalPath(), true);
          fileHandler.setLevel(Level.ALL);
          fileHandler.setFormatter(StaticLogFile.LogFileFormatter.newInstance());
          logger.addHandler(fileHandler);
      } catch (final Exception e) {
        LogUtil.logSevere(e);
View Full Code Here

Examples of java.util.logging.FileHandler

           
            final ConsoleHandler console = new TerminalConsoleHandler();
            global.addHandler(console);
           
            final File logFile = file;
            final FileHandler fileHandler = new FileHandler(
                    logFile.getAbsolutePath(), 500000, 5, true);
            fileHandler.setFormatter(new LogFormatter(true));
            global.addHandler(fileHandler);
           
            System.setOut(new PrintStream(System.out) {
               
               
View Full Code Here

Examples of java.util.logging.FileHandler

        String counts = props.getProperty(domain+PROP_LOGFILE_COUNT_SUFFIX);
        if (counts != null) {
            count = Integer.parseInt(counts);
        }

        FileHandler h = new FileHandler(logfile, limit, count, true);
        h.setFormatter(new LogSimpleFormatter(_logger));
        _logger.addHandler(h);

        _logger.log(Level.INFO, _jbr.getString(_jbr.I_LOG_DOMAIN, _name, domain));
        _logger.log(Level.INFO, _jbr.getString(_jbr.I_LOG_FILE, _name, logfile)+"["+limit+","+count+"]");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.