Search in sources :

Example 21 with Logger

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

the class LoggerTest method testLog_ParentNotInformed.

/*
	 * Test that the parent's handler is notified for a new log record when
	 * getUseParentHandlers() is false.
	 */
public void testLog_ParentNotInformed() {
    Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE);
    Logger parent = new MockParentLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
    child.setParent(parent);
    child.setLevel(Level.INFO);
    parent.setLevel(Level.INFO);
    parent.addHandler(new MockHandler());
    LogRecord r = new LogRecord(Level.INFO, "testLog_ParentInformed");
    child.setUseParentHandlers(false);
    child.log(r);
    assertFalse(child.getUseParentHandlers());
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger)

Example 22 with Logger

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

the class LoggerTest method testGetName_Normal.

/*
	 * Test setParent(Logger), having insufficient privilege.
	 *
	public void testSetParent_InsufficientPrivilege() {
		MockLogger log = new MockLogger(null, null);
		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());
		try {
			log.setParent(log);
			fail("Should throw SecurityException!");
		} catch (SecurityException e) {
		} finally {
			System.setSecurityManager(oldMan);
		}
	}

	/*
	 * Test setParent(Logger) with null, having insufficient privilege.
	 *
	public void testSetParent_InsufficientPrivilegeNull() {
		MockLogger log = new MockLogger(null, null);
		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());
		try {
			log.setParent(null);
			fail("Should throw NullPointerException!");
		} catch (NullPointerException e) {
		} finally {
			System.setSecurityManager(oldMan);
		}
	}

	/*
	 * Test setParent(Logger) for an anonymous logger with insufficient
	 * privilege.
	 *
	public void testSetParent_AnonyLoggerInsufficientPrivilege() {
		Logger log = Logger.getAnonymousLogger();
		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());
		try {
			log.setParent(log);
			fail("Should throw SecurityException!");
		} catch (SecurityException e) {
		} finally {
			System.setSecurityManager(oldMan);
		}
	}

	/*
	 * Test getName() for normal names.
	 */
public void testGetName_Normal() {
    Logger log = Logger.getLogger("testGetName_Normal");
    assertEquals("testGetName_Normal", log.getName());
    Logger mlog = new MockLogger("testGetName_Normal", null);
    assertEquals("testGetName_Normal", mlog.getName());
}
Also used : Logger(java.util.logging.Logger)

Example 23 with Logger

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

the class LoggerTest method testAddHandler_AnonyLoggerSufficientPrivilege.

/*
	 * Test addHandler(Handler) for a named logger with insufficient privilege.
	 *
	public void testAddHandler_NamedLoggerInsufficientPrivilege() {
		Logger log = Logger
				.getLogger("testAddHandler_NamedLoggerInsufficientPrivilege");
		MockHandler h = new MockHandler();
		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());

		try {
			log.addHandler(h);
			fail("Should throw SecurityException!");
		} catch (SecurityException e) {
		} finally {
			System.setSecurityManager(oldMan);
		}
	}

	/*
	 * Test addHandler(Handler) for a named logger with insufficient privilege,
	 * using a null handler.
	 *
	public void testAddHandler_NamedLoggerInsufficientPrivilegeNull() {
		Logger log = Logger
				.getLogger("testAddHandler_NamedLoggerInsufficientPrivilege");
		SecurityManager oldMan = System.getSecurityManager();
		System.setSecurityManager(new MockSecurityManager());

		try {
			log.addHandler(null);
			fail("Should throw NullPointerException!");
		} catch (NullPointerException e) {
		} finally {
			System.setSecurityManager(oldMan);
		}
	}

	/*
	 * Test addHandler(Handler) for an anonymous logger with sufficient
	 * privilege.
	 */
public void testAddHandler_AnonyLoggerSufficientPrivilege() {
    Logger log = Logger.getAnonymousLogger();
    MockHandler h = new MockHandler();
    assertEquals(log.getHandlers().length, 0);
    log.addHandler(h);
    assertEquals(log.getHandlers().length, 1);
    assertSame(log.getHandlers()[0], h);
}
Also used : Logger(java.util.logging.Logger)

Example 24 with Logger

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

the class LoggerTest method testGetAnonymousLogger_ValidResourceBundle.

/*
	 * Test getAnonymousLogger(String resourceBundleName) with valid resource
	 * bundle.
	 */
public void testGetAnonymousLogger_ValidResourceBundle() {
    Logger alog = Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE);
    assertNotSame(alog, Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE));
    assertNull(alog.getFilter());
    assertEquals(0, alog.getHandlers().length);
    assertNull(alog.getLevel());
    assertNull(alog.getName());
    assertNull(alog.getParent().getParent());
    assertEquals(VALID_VALUE, alog.getResourceBundle().getString(VALID_KEY));
    assertEquals(alog.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
    assertTrue(alog.getUseParentHandlers());
}
Also used : Logger(java.util.logging.Logger)

Example 25 with Logger

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

the class LoggerTest method testLog_NullResHasParent.

/*
	 * Test that a logger inherits its parent resource bundle when its resource
	 * bundle is null.
	 */
public void testLog_NullResHasParent() {
    Logger child = new MockLogger("childLogger", null);
    Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
    child.addHandler(new MockHandler());
    child.setParent(parent);
    parent.setLevel(Level.FINER);
    assertNull(child.getResourceBundle());
    assertNull(child.getResourceBundleName());
    child.log(Level.FINE, "testLog_NullResHasParent");
    // pop only once, pushed by the child logger's handler
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), "childLogger");
    assertEquals(r.getMessage(), "testLog_NullResHasParent");
    assertSame(r.getResourceBundleName(), VALID_RESOURCE_BUNDLE2);
    assertSame(r.getSourceClassName(), null);
    assertSame(r.getSourceMethodName(), null);
    assertSame(r.getLevel(), Level.FINE);
    assertNull(r.getParameters());
    assertSame(r.getThrown(), null);
    assertNull(child.getResourceBundle());
    assertNull(child.getResourceBundleName());
}
Also used : LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger)

Aggregations

Logger (java.util.logging.Logger)499 Test (org.junit.Test)70 LogRecord (java.util.logging.LogRecord)60 ActionReport (org.glassfish.api.ActionReport)56 Handler (java.util.logging.Handler)52 IOException (java.io.IOException)37 File (java.io.File)36 Level (java.util.logging.Level)25 ArrayList (java.util.ArrayList)22 ConsoleHandler (java.util.logging.ConsoleHandler)19 Properties (java.util.Properties)15 SimpleFormatter (java.util.logging.SimpleFormatter)15 Config (com.sun.enterprise.config.serverbeans.Config)14 HashMap (java.util.HashMap)14 Map (java.util.Map)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ResourceBundle (java.util.ResourceBundle)11 LogManager (java.util.logging.LogManager)11 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10