Search in sources :

Example 31 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testPublish_AfterResetSystemErr.

/*
	 * Test publish(), after system err is reset.
	 */
public void testPublish_AfterResetSystemErr() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    h.setFilter(new MockFilter());
    System.setErr(new PrintStream(new ByteArrayOutputStream()));
    LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertSame(r, CallVerificationStack.getInstance().pop());
    assertEquals("", this.errSubstituteStream.toString());
}
Also used : PrintStream(java.io.PrintStream) LogRecord(java.util.logging.LogRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 32 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testPublish_WithFilter.

/*
	 * Test publish(), use a filter, having output stream, normal log record.
	 */
public void testPublish_WithFilter() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    h.setFilter(new MockFilter());
    LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertSame(r, CallVerificationStack.getInstance().pop());
    assertEquals("", this.errSubstituteStream.toString());
    h.setLevel(Level.WARNING);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertTrue(CallVerificationStack.getInstance().empty());
    assertEquals("", this.errSubstituteStream.toString());
    h.setLevel(Level.CONFIG);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertSame(r, CallVerificationStack.getInstance().pop());
    assertEquals("", this.errSubstituteStream.toString());
    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertEquals("", this.errSubstituteStream.toString());
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 33 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testPublish_NoFilter.

/*
	 * Test close() when having insufficient privilege.
	 *
	public void testClose_InsufficientPrivilege() throws Exception {
		Properties p = new Properties();
		p.put("java.util.logging.ConsoleHandler.formatter", className
				+ "$MockFormatter");
		LogManager.getLogManager().readConfiguration(
				EnvironmentHelper.PropertiesToInputStream(p));
		ConsoleHandler h = new ConsoleHandler();
		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());
		try {
			h.close();
		} finally {
			System.setSecurityManager(oldMan);
		}
	}
	*/
/*
	 * Test publish(), use no filter, having output stream, normal log record.
	 */
public void testPublish_NoFilter() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    h.flush();
    assertEquals("MockFormatter_Head" + "testPublish_NoFilter", this.errSubstituteStream.toString());
    h.setLevel(Level.WARNING);
    h.publish(r);
    h.flush();
    assertEquals("MockFormatter_Head" + "testPublish_NoFilter", this.errSubstituteStream.toString());
    h.setLevel(Level.CONFIG);
    h.publish(r);
    h.flush();
    assertEquals("MockFormatter_Head" + "testPublish_NoFilter" + "testPublish_NoFilter", this.errSubstituteStream.toString());
    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    h.publish(r);
    h.flush();
    assertEquals("MockFormatter_Head" + "testPublish_NoFilter" + "testPublish_NoFilter", this.errSubstituteStream.toString());
}
Also used : LogRecord(java.util.logging.LogRecord) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 34 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testPublish_AfterClose.

public void testPublish_AfterClose() throws Exception {
    PrintStream backup = System.err;
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        System.setErr(new PrintStream(bos));
        Properties p = new Properties();
        p.put("java.util.logging.ConsoleHandler.level", "FINE");
        p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
        LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
        ConsoleHandler h = new ConsoleHandler();
        assertSame(h.getLevel(), Level.FINE);
        LogRecord r1 = new LogRecord(Level.INFO, "testPublish_Record1");
        LogRecord r2 = new LogRecord(Level.INFO, "testPublish_Record2");
        assertTrue(h.isLoggable(r1));
        h.publish(r1);
        assertTrue(bos.toString().indexOf("testPublish_Record1") >= 0);
        h.close();
        // assertFalse(h.isLoggable(r));
        assertTrue(h.isLoggable(r2));
        h.publish(r2);
        assertTrue(bos.toString().indexOf("testPublish_Record2") >= 0);
        h.flush();
    // assertEquals("MockFormatter_Head",
    // this.errSubstituteStream.toString());
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        System.setErr(backup);
    }
}
Also used : PrintStream(java.io.PrintStream) LogRecord(java.util.logging.LogRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 35 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testConstructor_NoProperties.

/*
	 * Test the constructor with no relevant log manager properties are set.
	 */
public void testConstructor_NoProperties() {
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.level"));
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.filter"));
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.formatter"));
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.encoding"));
    ConsoleHandler h = new ConsoleHandler();
    assertSame(h.getLevel(), Level.INFO);
    assertTrue(h.getFormatter() instanceof SimpleFormatter);
    assertNull(h.getFilter());
    assertSame(h.getEncoding(), null);
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) ConsoleHandler(java.util.logging.ConsoleHandler)

Aggregations

ConsoleHandler (java.util.logging.ConsoleHandler)54 Handler (java.util.logging.Handler)23 Logger (java.util.logging.Logger)17 LogRecord (java.util.logging.LogRecord)13 Properties (java.util.Properties)12 IOException (java.io.IOException)7 FileHandler (java.util.logging.FileHandler)6 File (java.io.File)5 PrintStream (java.io.PrintStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SimpleFormatter (java.util.logging.SimpleFormatter)4 ArrayList (java.util.ArrayList)2 JarFile (java.util.jar.JarFile)2 Formatter (java.util.logging.Formatter)2 Level (java.util.logging.Level)2 CommandCenterLogic (alma.acs.commandcenter.app.CommandCenterLogic)1 StartupOptions (alma.acs.commandcenter.app.CommandCenterLogic.StartupOptions)1 JmeFormatter (com.jme3.util.JmeFormatter)1 ClassFileLoader (com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoader)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1