use of java.util.logging.Handler in project pcgen by PCGen.
the class SourceFileLoader method execute.
@Override
public void execute() {
Globals.emptyLists();
SettingsHandler.setGame(selectedGame.getName());
Globals.initPreferences();
Globals.emptyLists();
Handler handler = new LoadHandler();
Logging.registerHandler(handler);
try {
loadCampaigns();
} catch (PersistenceLayerException e) {
Logging.errorPrint("Failed to load sources", e);
uiDelegate.showErrorMessage(Constants.APPLICATION_NAME, "Failed to load sources, see log for details.");
}
Logging.removeHandler(handler);
}
use of java.util.logging.Handler in project ACS by ACS-Community.
the class ClientLogManagerTest method assertLogLevels.
/**
* Checks that an AcsLogger has local and remote handlers configured with the correct levels.
*/
private void assertLogLevels(AcsLogger logger, AcsLogLevelDefinition expectedLocalLevel, AcsLogLevelDefinition expectedRemoteLevel) {
Handler[] handlers = logger.getHandlers();
assertTrue(handlers.length == 2);
StdOutConsoleHandler localHandler = null;
AcsLoggingHandler remoteHandler = null;
for (Handler handler : handlers) {
if (handler instanceof StdOutConsoleHandler) {
localHandler = (StdOutConsoleHandler) handler;
} else if (handler instanceof AcsLoggingHandler) {
remoteHandler = (AcsLoggingHandler) handler;
} else {
fail("Unexpected handler type " + handler.getClass().getName() + " encountered.");
}
}
assertNotNull(localHandler);
assertNotNull(remoteHandler);
assertEquals(AcsLogLevel.getLowestMatchingJdkLevel(expectedLocalLevel), localHandler.getLevel());
assertEquals(AcsLogLevel.getLowestMatchingJdkLevel(expectedRemoteLevel), remoteHandler.getLevel());
}
use of java.util.logging.Handler in project ACS by ACS-Community.
the class ClientLogManagerTest method testLoggerStructure.
public void testLoggerStructure() {
Logger containerLogger = clientLogManager.getLoggerForContainer("test");
assertNotNull(containerLogger);
Logger acsRemoteLogger = containerLogger.getParent();
assertNotNull(acsRemoteLogger);
assertFalse(acsRemoteLogger.getUseParentHandlers());
Logger rootLogger = acsRemoteLogger.getParent();
assertNotNull(rootLogger);
assertNull(rootLogger.getParent());
Handler[] handlers = containerLogger.getHandlers();
assertTrue(handlers.length == 2);
StdOutConsoleHandler localHandler = null;
AcsLoggingHandler remoteHandler = null;
for (Handler handler : handlers) {
if (handler instanceof StdOutConsoleHandler) {
localHandler = (StdOutConsoleHandler) handler;
} else if (handler instanceof AcsLoggingHandler) {
remoteHandler = (AcsLoggingHandler) handler;
} else {
fail("Unexpected handler type " + handler.getClass().getName() + " encountered.");
}
}
assertNotNull(localHandler);
assertNotNull(remoteHandler);
Formatter localFormatter = localHandler.getFormatter();
assertTrue("localFormatter should not be of type " + localFormatter.getClass().getName(), localFormatter instanceof ConsoleLogFormatter);
Handler[] parentHandlers = acsRemoteLogger.getHandlers();
assertTrue(parentHandlers.length == 0);
assertEquals(AcsLogLevel.DELOUSE, remoteHandler.getLevel());
containerLogger.info("I'm a good pedigree logger.");
}
use of java.util.logging.Handler in project ACS by ACS-Community.
the class ShutdownHookTest method main.
/**
* Creates the ComponentClient "ShutdownHookTestClient" and tests its cleanup
* using calls to tearDown coming both from the shutdown hook and from explicit invocations.
* <p>
* In the <code>tearDown</code> method, it enables FINE logs for stdout
* before calling {@link ComponentClient#tearDown()},
* in order to not miss the "duplicate call" log that the base class creates
* if <code>tearDown</code> is called more than once.
* <p>
* Meaning of the 3 int args:
* <ol>
* <li> <code>0</code>: tearDown calls super.tearDown and exits. <br>
* <code>!=0</code>: tearDown sleeps 10 seconds after calling super.tearDown
* <li> Sleep time in seconds after creating the ComponentClient, before returning from this main method call.
* <li> Number of additional calls to the ComponentClient's tearDown method.
* </ol>
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
AcsLogger logger;
ComponentClient m_client;
logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("ShutdownHookTestClient", false);
if (Integer.parseInt(args[0]) == 0)
m_client = new ComponentClient(logger, AcsLocations.figureOutManagerLocation(), "ShutdownHookTestClient") {
public void tearDown() throws Exception {
for (Handler h : m_logger.getHandlers()) {
if (h instanceof StdOutConsoleHandler) {
// to get the "duplicate call" log
h.setLevel(Level.FINE);
}
}
super.tearDown();
}
};
else
m_client = new ComponentClient(logger, AcsLocations.figureOutManagerLocation(), "ShutdownHookTestClient") {
public void tearDown() throws Exception {
for (Handler h : m_logger.getHandlers()) if (h instanceof StdOutConsoleHandler) {
// to get the "duplicate call" log
h.setLevel(Level.FINE);
}
super.tearDown();
Thread.sleep(10 * 1000);
}
};
// Sleep a little bit... depending on the amount of time, we might want to kill
// this baby from the outside, who knows
Thread.sleep(Integer.parseInt(args[1]) * 1000);
// We may want to call tearDown() as many times as we want
int iterations = Integer.parseInt(args[2]);
for (int i = 0; i != iterations; i++) {
m_client.tearDown();
}
}
use of java.util.logging.Handler in project ACS by ACS-Community.
the class AcsLoggerTest method testWrapJdkLogger.
public void testWrapJdkLogger() {
assertSame("Expected reuse of AcsLogger", acsLogger, AcsLogger.fromJdkLogger(acsLogger, null));
Logger jdkLogger = TestLogger.getLogger("myJdkLogger");
Handler[] handlers = jdkLogger.getHandlers();
assertEquals(1, handlers.length);
// to get an ISO timestamp on stdout, for TAT/sed filtering.
handlers[0].setFormatter(new ConsoleLogFormatter());
AcsLogger wrapper = AcsLogger.fromJdkLogger(jdkLogger, null);
assertEquals("myJdkLoggerwrapper", wrapper.getName());
wrapper.info("A message logged by the AcsLogger that wraps the jdkLogger");
}
Aggregations