Search in sources :

Example 46 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 47 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 48 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 49 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)

Example 50 with Handler

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

Aggregations

Handler (java.util.logging.Handler)108 Logger (java.util.logging.Logger)35 ConsoleHandler (java.util.logging.ConsoleHandler)22 LogRecord (java.util.logging.LogRecord)16 Test (org.junit.Test)15 FileHandler (java.util.logging.FileHandler)13 IOException (java.io.IOException)9 File (java.io.File)8 Level (java.util.logging.Level)7 SimpleFormatter (java.util.logging.SimpleFormatter)7 Formatter (java.util.logging.Formatter)6 LogManager (java.util.logging.LogManager)6 PrintStream (java.io.PrintStream)5 ArrayList (java.util.ArrayList)4 SLF4JBridgeHandler (org.slf4j.bridge.SLF4JBridgeHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 StringTokenizer (java.util.StringTokenizer)3 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)2 ConsoleLogFormatter (alma.acs.logging.formatters.ConsoleLogFormatter)2 MonitoredResource (com.google.cloud.MonitoredResource)2