Search in sources :

Example 46 with Logger

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

the class LoggerTest method testRemoveHandler_AnonyLoggerSufficientPrivilege.

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

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

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

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

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

Example 47 with Logger

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

the class LoggerTest method testGetName_Empty.

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

Example 48 with Logger

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

the class LoggerTest method testGetResourceBundle_Null.

/*
	 * Test getResourceBundle() when it it null.
	 */
public void testGetResourceBundle_Null() {
    Logger log = Logger.getLogger("testGetResourceBundle_Null", null);
    assertNull(log.getResourceBundle());
    Logger mlog = new MockLogger(null, null);
    assertNull(mlog.getResourceBundle());
}
Also used : Logger(java.util.logging.Logger)

Example 49 with Logger

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

the class LoggerTest method testGetLoggerWithRes_ExistingLoggerWithSameRes.

/*
	 * Test getLogger(String, String) with valid resource bundle, to get an
	 * existing logger with the same associated resource bundle.
	 */
public void testGetLoggerWithRes_ExistingLoggerWithSameRes() {
    assertNull(LogManager.getLogManager().getLogger("testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger"));
    // create a new logger
    Logger log1 = Logger.getLogger("testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger", VALID_RESOURCE_BUNDLE);
    // get an existing logger
    Logger log2 = Logger.getLogger("testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger", VALID_RESOURCE_BUNDLE);
    assertSame(log1, log2);
    assertEquals(VALID_VALUE, log1.getResourceBundle().getString(VALID_KEY));
    assertEquals(log1.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
}
Also used : Logger(java.util.logging.Logger)

Example 50 with Logger

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

the class LoggerTest method testFinest_Null.

/*
	 * Test finest(String) with null values.
	 */
public void testFinest_Null() {
    Logger child = new MockLogger("childLogger", null);
    Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
    child.addHandler(new MockHandler());
    child.setParent(parent);
    child.setLevel(Level.FINEST);
    child.finest(null);
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), child.getName());
    assertNull(r.getMessage());
    assertSame(r.getResourceBundleName(), parent.getResourceBundleName());
    assertSame(r.getResourceBundle(), parent.getResourceBundle());
    assertSame(r.getSourceClassName(), null);
    assertSame(r.getSourceMethodName(), null);
    assertSame(r.getLevel(), Level.FINEST);
    assertNull(r.getParameters());
    assertSame(r.getThrown(), null);
    this.sharedLogger.setLevel(Level.FINER);
    this.sharedLogger.finest(null);
    assertTrue(CallVerificationStack.getInstance().empty());
}
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