Search in sources :

Example 66 with Handler

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);
}
Also used : LogRecord(java.util.logging.LogRecord) SubscriberExceptionHandler(com.google.common.eventbus.SubscriberExceptionHandler) Handler(java.util.logging.Handler) InterruptSignalHandler(com.google.devtools.build.lib.server.signal.InterruptSignalHandler) Logger(java.util.logging.Logger) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 67 with Handler

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);
}
Also used : Handler(java.util.logging.Handler) LogManager(java.util.logging.LogManager) BeforeClass(org.junit.BeforeClass)

Example 68 with Handler

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();
        }
    }
}
Also used : FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) FileHandler(java.util.logging.FileHandler)

Example 69 with Handler

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);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) Handler(java.util.logging.Handler) File(java.io.File) FileInputStream(java.io.FileInputStream) MissingResourceException(java.util.MissingResourceException)

Example 70 with Handler

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();
    }
}
Also used : Handler(java.util.logging.Handler) Logger(java.util.logging.Logger)

Aggregations

Handler (java.util.logging.Handler)135 Logger (java.util.logging.Logger)52 ConsoleHandler (java.util.logging.ConsoleHandler)30 LogRecord (java.util.logging.LogRecord)24 Test (org.junit.Test)22 FileHandler (java.util.logging.FileHandler)17 File (java.io.File)14 IOException (java.io.IOException)13 Level (java.util.logging.Level)11 SimpleFormatter (java.util.logging.SimpleFormatter)8 Formatter (java.util.logging.Formatter)7 LogManager (java.util.logging.LogManager)6 PrintStream (java.io.PrintStream)5 ArrayList (java.util.ArrayList)5 SLF4JBridgeHandler (org.slf4j.bridge.SLF4JBridgeHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 StringTokenizer (java.util.StringTokenizer)3 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)2