use of java.util.logging.Handler in project jmonkeyengine by jMonkeyEngine.
the class TestCanvas method main.
public static void main(String[] args) {
JmeFormatter formatter = new JmeFormatter();
Handler consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(formatter);
Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
Logger.getLogger("").addHandler(consoleHandler);
createCanvas(appClass);
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
createFrame();
currentPanel.add(canvas, BorderLayout.CENTER);
frame.pack();
startApp();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
use of java.util.logging.Handler in project j2objc by google.
the class LoggerTest method test_initHandler.
/*
* Test whether privileged code is used to load resource bundles.
*
public void testLoadResourceBundle() {
//
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockNoLoadingClassSecurityManager());
try {
Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE);
} finally {
System.setSecurityManager(oldMan);
}
}
public void testLoadResourceBundleNonExistent() {
try {
// Try a load a non-existent resource bundle.
LoggerExtension.loadResourceBundle("missinglogger.properties");
fail("Expected an exception.");
} catch (MissingResourceException ex) {
// Expected exception is precisely a MissingResourceException
assertTrue(ex.getClass() == MissingResourceException.class);
}
}
/**
* @tests java.util.logging.Logger#logrb(Level, String, String, String,
* String, Object)
*
public void test_init_logger()
throws Exception {
Properties p = new Properties();
p.put("testGetLogger_Normal_ANewLogger2.level", "ALL");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
assertNull(LogManager.getLogManager().getLogger(
"testGetLogger_Normal_ANewLogger2"));
SecurityManager originalSecurityManager = System.getSecurityManager();
try {
System.setSecurityManager(new SecurityManager());
// should not throw expection
Logger logger = Logger.getLogger("testGetLogger_Normal_ANewLogger2");
// should thrpw exception
try{
logger.setLevel(Level.ALL);
fail("should throw SecurityException");
} catch (SecurityException e){
// expected
}
try{
logger.setParent(Logger.getLogger("root"));
fail("should throw SecurityException");
} catch (SecurityException e){
// expected
}
} finally {
System.setSecurityManager(originalSecurityManager);
}
}
/*
* test initHandler
*/
public void test_initHandler() throws Exception {
InputStream logProps = ClassLoader.getSystemResourceAsStream(LOGGING_CONFIG_FILE);
LogManager lm = LogManager.getLogManager();
lm.readConfiguration(logProps);
Logger log = Logger.getLogger("");
// can log properly
Handler[] handlers = log.getHandlers();
assertEquals(2, handlers.length);
}
use of java.util.logging.Handler in project meteo by pierre.
the class SetupJULBridge method contextInitialized.
@Override
public void contextInitialized(final ServletContextEvent event) {
// we first remove the default handler(s)
final Logger rootLogger = LogManager.getLogManager().getLogger("");
final Handler[] handlers = rootLogger.getHandlers();
if (!ArrayUtils.isEmpty(handlers)) {
for (final Handler handler : handlers) {
rootLogger.removeHandler(handler);
}
}
// and then we let jul-to-sfl4j do its magic so that jersey messages go to sfl4j (and thus log4j)
SLF4JBridgeHandler.install();
log.info("Assimilated java.util Logging");
}
use of java.util.logging.Handler in project heron by twitter.
the class LoggingHelper method loggerInit.
/**
* Init java util logging
*
* @param level the Level of message to log
* @param isRedirectStdOutErr whether we redirect std out&err
* @param format the format to log
*/
public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException {
// Set the java util logging format
setLoggingFormat(format);
// Configure the root logger and its handlers so that all the
// derived loggers will inherit the properties
Logger rootLogger = Logger.getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
handler.setLevel(level);
}
rootLogger.setLevel(level);
if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) {
// zookeeper logging scares me. if people want this, we can patch to config-drive this
Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING);
}
if (isRedirectStdOutErr) {
// System.err to Logger, it results in an infinite loop.
for (Handler handler : rootLogger.getHandlers()) {
if (handler instanceof ConsoleHandler) {
rootLogger.removeHandler(handler);
}
}
// now rebind stdout/stderr to logger
Logger logger;
LoggingOutputStream los;
logger = Logger.getLogger("stdout");
los = new LoggingOutputStream(logger, StdOutErrLevel.STDOUT);
System.setOut(new PrintStream(los, true));
logger = Logger.getLogger("stderr");
los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR);
System.setErr(new PrintStream(los, true));
}
}
use of java.util.logging.Handler in project commons by twitter.
the class RootLogConfigTest method setUp.
@Before
public void setUp() {
// Intercept stderr (this must be done first).
fakeErrorLog = new ByteArrayOutputStream();
errPrintStream = new PrintStream(fakeErrorLog);
System.setErr(errPrintStream);
// Create other members
consoleHandler = new ConsoleHandler();
fakeFileLog = new FakeHandler();
// Emulate default setup (just a console handler), but avoiding the use
// of the global root logger so not to get a flaky test due to background threads.
fakeRootLogger = Logger.getLogger("FakeRoot-" + UUID.randomUUID().toString());
fakeRootLogger.setUseParentHandlers(false);
for (Handler h : fakeRootLogger.getHandlers()) {
fakeRootLogger.removeHandler(h);
}
fakeRootLogger.addHandler(consoleHandler);
testLogger = Logger.getLogger(RootLogConfigTest.class.getName());
testLogger.setUseParentHandlers(true);
testLogger.setParent(fakeRootLogger);
setFakeRootForLogger(ClassA.logger);
setFakeRootForLogger(ClassB.logger);
resetLogs();
}
Aggregations