use of java.util.logging.Handler in project bazel by bazelbuild.
the class BlazeRuntime method getTestCrashLogger.
/**
* Returns a logger that crashes as soon as it's written to, since tests should not cause events
* that would be logged.
*/
@VisibleForTesting
public static Future<Logger> getTestCrashLogger() {
Logger crashLogger = Logger.getAnonymousLogger();
crashLogger.addHandler(new Handler() {
@Override
public void publish(LogRecord record) {
System.err.println("Remote logging disabled for testing, forcing abrupt shutdown.");
System.err.printf("%s#%s: %s\n", record.getSourceClassName(), record.getSourceMethodName(), record.getMessage());
Throwable e = record.getThrown();
if (e != null) {
e.printStackTrace();
}
Runtime.getRuntime().halt(ExitCode.BLAZE_INTERNAL_ERROR.getNumericExitCode());
}
@Override
public void flush() {
throw new IllegalStateException();
}
@Override
public void close() {
throw new IllegalStateException();
}
});
return Futures.immediateFuture(crashLogger);
}
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 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 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 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();
}
}
Aggregations