use of java.util.logging.Handler in project jetty.project by eclipse.
the class JavaUtilLogTest method setJUL.
@BeforeClass
public static void setJUL() {
LogManager lmgr = LogManager.getLogManager();
java.util.logging.Logger root = lmgr.getLogger("");
// Remember original handlers
originalHandlers = root.getHandlers();
// Remove original handlers
for (Handler existing : originalHandlers) {
root.removeHandler(existing);
}
// Set test/capturing handler
jul = new CapturingJULHandler();
root.addHandler(jul);
}
use of java.util.logging.Handler in project gephi by gephi.
the class ReportController method logMessageLog.
private void logMessageLog(Report report) {
System.out.flush();
// NOI18N
String ud = System.getProperty("netbeans.user");
if (ud == null || "memory".equals(ud)) {
// NOI18N
return;
}
Handler[] handlers = Logger.getLogger("").getHandlers();
handlers[0].flush();
// NOI18N
File userDir = new File(ud);
File directory = new File(new File(userDir, "var"), "log");
File messagesLog = new File(directory, "messages.log");
String log = "";
try {
byte[] buffer = new byte[(int) messagesLog.length()];
BufferedInputStream f = new BufferedInputStream(new FileInputStream(messagesLog));
f.read(buffer);
log = new String(buffer);
} catch (Exception e) {
}
report.setLog(log);
}
use of java.util.logging.Handler in project buck by facebook.
the class JavaUtilsLoggingBuildListener method closeLogFile.
public static void closeLogFile() {
for (Handler handler : LOG.getHandlers()) {
if (handler instanceof FileHandler) {
LOG.removeHandler(handler);
handler.close();
}
}
}
use of java.util.logging.Handler in project buck by facebook.
the class LogConfig method flushLogs.
public static void flushLogs() {
Logger rootLogger = LogManager.getLogManager().getLogger("");
if (rootLogger == null) {
return;
}
Handler[] handlers = rootLogger.getHandlers();
if (handlers == null) {
return;
}
for (Handler h : Arrays.asList(handlers)) {
h.flush();
}
}
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);
}
Aggregations