當前位置: 首頁>>代碼示例>>Java>>正文


Java LogManager類代碼示例

本文整理匯總了Java中java.util.logging.LogManager的典型用法代碼示例。如果您正苦於以下問題:Java LogManager類的具體用法?Java LogManager怎麽用?Java LogManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LogManager類屬於java.util.logging包,在下文中一共展示了LogManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import java.util.logging.LogManager; //導入依賴的package包/類
@Override
public void run() {
    while (goOn) {
        try {
            if (Math.random() > CONFSYNCTHRESHOLD) {
                // calling readConfiguration while holding a lock can
                // increase deadlock probability...
                synchronized(fakeConfExternalLock()) {
                    LogManager.getLogManager().readConfiguration();
                }
            } else {
                LogManager.getLogManager().readConfiguration();
            }
            Logger blah = Logger.getLogger(BLAH);
            blah.setLevel(Level.FINEST);
            blah.fine(BLAH);
            readCount.incrementAndGet();
            pause(1);
        } catch (Exception x) {
            fail(x);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:TestConfigurationLock.java

示例2: get

import java.util.logging.LogManager; //導入依賴的package包/類
public static ClassLogger get(@Nullable Logger parent, Class<?> klass, @Nullable String instanceKey) {
    if(parent == null) {
        parent = Logger.getLogger("");
    }

    ClassLogger logger = find(parent, klass, instanceKey);
    if(logger == null) {
        logger = new ClassLogger(parent, klass, instanceKey);
        // TODO: call addLogger from the constructuor, when it's no longer public
        final LogManager logManager = LogManager.getLogManager();
        if(logManager.addLogger(logger)) {
            // addLogger will set the parent, so we have to set it back again
            logger.setParent(parent);
        } else {
            // Logger was created by another thread
            logger = find(parent, klass, instanceKey);
            if(logger == null) {
                throw new IllegalStateException("Failed to register logger " + getName(klass, instanceKey));
            }
        }
    }

    return logger;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:25,代碼來源:ClassLogger.java

示例3: configure

import java.util.logging.LogManager; //導入依賴的package包/類
static void configure(Level lev, String root, NbTestCase current) {
    IL il = new IL(false);
    
    String c = "handlers=" + Log.class.getName() + "\n" +
               root + ".level=" + lev.intValue() + "\n";

    ByteArrayInputStream is = new ByteArrayInputStream(c.getBytes());
    try {
        LogManager.getLogManager().readConfiguration(is);
    } catch (IOException ex) {
        // exception
        ex.printStackTrace();
    }

    Log.current = current;
    Log.messages.setLength(0);
    Log.messages.append("Starting test ");
    Log.messages.append(current.getName());
    Log.messages.append('\n');
    Log.initialMessages = Log.messages.length();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:Log.java

示例4: main

import java.util.logging.LogManager; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException{
    Thread t1 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger Logger.<clinit>
            Logger.getAnonymousLogger();
        }
    });

    Thread t2 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger LogManager.<clinit>
            LogManager.getLogManager();
        }
    });

    t1.start();
    t2.start();

    t1.join();
    t2.join();
    System.out.println("\nTest passed");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:LoggingDeadlock.java

示例5: testCanInfluenceBehaviourBySettingALevelPropertyOnParent

import java.util.logging.LogManager; //導入依賴的package包/類
public void testCanInfluenceBehaviourBySettingALevelPropertyOnParent() throws Exception {
    System.setProperty("ha.nu.level", "100");
    Reference<?> ref = new WeakReference<Object>(Logger.getLogger("ha.nu.wirta"));
    assertGC("ha.nu.wirta should not exist after this line", ref);
    
    LogManager.getLogManager().readConfiguration();

    final Logger log = Logger.getLogger("ha.nu.wirta");
    log.log(Level.FINER, "Finer level msg");

    Pattern p = Pattern.compile("FINER.*Finer level msg");
    String disk = readLog(true);
    Matcher d = p.matcher(disk);

    if (!d.find()) {
        fail("msg shall be logged to file: " + disk);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:TopLoggingTest.java

示例6: testCanInfluenceBehaviourBySettingALevelPropertyOnExistingParent

import java.util.logging.LogManager; //導入依賴的package包/類
public void testCanInfluenceBehaviourBySettingALevelPropertyOnExistingParent() throws Exception {
    System.setProperty("ha.nu.level", "100");

    Logger l = Logger.getLogger("ha.nu.wirta");

    LogManager.getLogManager().readConfiguration();

    l.log(Level.FINER, "Finer level msg");

    Pattern p = Pattern.compile("FINER.*Finer level msg");
    String disk = readLog(true);
    Matcher d = p.matcher(disk);

    if (!d.find()) {
        fail("msg shall be logged to file: " + disk);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:TopLoggingTest.java

示例7: Cfg

import java.util.logging.LogManager; //導入依賴的package包/類
public Cfg() throws IOException {

            ByteArrayOutputStream os = new ByteArrayOutputStream();
            OutputStreamWriter w = new OutputStreamWriter(os);
            w.write("handlers=java.util.logging.FileHandler\n");
            w.write(".level=100\n");
            w.write("java.util.logging.FileHandler.pattern=" + log.toString().replace('\\', '/') +"\n");
            w.close();

            LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(os.toByteArray()));
            
        }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:TopLoggingOwnConfigClassTest.java

示例8: testLog

import java.util.logging.LogManager; //導入依賴的package包/類
public void testLog() throws Exception {
    assertFalse(err.isLoggable(ErrorManager.INFORMATIONAL));
    err.log("some msg");
    String s = readLog();
    assertTrue(s.indexOf("some msg") == -1);
    assertTrue(err.isLoggable(ErrorManager.WARNING));
    err.log(ErrorManager.WARNING, "another msg");
    s = readLog();
    assertTrue(s.indexOf("another msg") != -1);
    ErrorManager err2 = err.getInstance("foo.bar.baz");
    assertFalse(err2.isLoggable(ErrorManager.INFORMATIONAL));
    err2.log("sub msg #1");
    s = readLog();
    assertTrue(s.indexOf("sub msg #1") == -1);
    System.setProperty("quux.hoho.level", "0");

    LogManager.getLogManager().readConfiguration();

    err2 = err.getInstance("quux.hoho.yaya");
    assertTrue(err2.isLoggable(ErrorManager.INFORMATIONAL));
    err2.log("sub msg #2");
    s = readLog();
    assertTrue(s, s.indexOf("sub msg #2") != -1);
    assertTrue(s, s.indexOf("quux.hoho.yaya") != -1);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:NbErrorManagerTest.java

示例9: readLog

import java.util.logging.LogManager; //導入依賴的package包/類
private String readLog() throws IOException {
    LogManager.getLogManager().readConfiguration();

    File log = new File(new File(new File(getWorkDir(), "var"), "log"), "messages.log");
    assertTrue("Log file exists: " + log, log.canRead());

    FileInputStream is = new FileInputStream(log);

    byte[] arr = new byte[(int)log.length()];
    int r = is.read(arr);
    assertEquals("all read", arr.length, r);
    is.close();

    new FileOutputStream(log).close(); // truncate

    return "---%<--- [start log of " + getName() + "]\n" + new String(arr).replaceFirst("\0+", "") + "\n---%<--- [end log of " + getName() + "]\n";
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:NbErrorManagerTest.java

示例10: LoggingConfig

import java.util.logging.LogManager; //導入依賴的package包/類
public LoggingConfig() {
    try {
        // Load a properties file from class path java.util.logging.config.file
        final LogManager logManager = LogManager.getLogManager();
        URL configURL = getClass().getResource("/logging.properties");
        if (configURL != null) {
            try (InputStream is = configURL.openStream()) {
                logManager.readConfiguration(is);
            }
        } else {
            // Programmatic configuration
            System.setProperty("java.util.logging.SimpleFormatter.format",
                               "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s [%3$s] %5$s %6$s%n");

            final ConsoleHandler consoleHandler = new ConsoleHandler();
            consoleHandler.setLevel(Level.FINEST);
            consoleHandler.setFormatter(new SimpleFormatter());

            final Logger app = Logger.getLogger("app");
            app.setLevel(Level.FINEST);
            app.addHandler(consoleHandler);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:fabric8-launcher,項目名稱:launcher-backend,代碼行數:27,代碼來源:LoggingConfig.java

示例11: execute

import java.util.logging.LogManager; //導入依賴的package包/類
public void execute(Runnable run) {
    System.out.println("Running test case: " + name());
    try {
       Configure.setUp(this);
       Configure.doPrivileged(run, SimplePolicy.allowControl);
    } finally {
       Configure.doPrivileged(() -> {
           try {
               setSystemProperty("java.util.logging.config.file", null);
               LogManager.getLogManager().readConfiguration();
               System.gc();
           } catch (Exception x) {
               throw new RuntimeException(x);
           }
       }, SimplePolicy.allowAll);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:SimpleUpdateConfigWithInputStreamTest.java

示例12: testFive

import java.util.logging.LogManager; //導入依賴的package包/類
public static void testFive() {
    for (int i=0; i<3 ; i++) {
        Logger logger1 = LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME);
        Logger logger1b = LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME);
        assertNotNull(logger1);
        assertNotNull(logger1b);
        assertEquals(logger1, logger1b);

        Bridge.changeContext();

        Logger logger2 = LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME);
        Logger logger2b = LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME);
        assertNotNull(logger2);
        assertNotNull(logger2b);
        assertEquals(logger2, logger2b);

        assertEquals(logger1, logger2);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:TestAppletLoggerContext.java

示例13: run

import java.util.logging.LogManager; //導入依賴的package包/類
@Override
public void run() {
    try {
        if (getServer() != null) {
            Catalina.this.stop();
        }
    } catch (Throwable ex) {
        ExceptionUtils.handleThrowable(ex);
        log.error(sm.getString("catalina.shutdownHookFail"), ex);
    } finally {
        // If JULI is used, shut JULI down *after* the server shuts down
        // so log messages aren't lost
        LogManager logManager = LogManager.getLogManager();
        if (logManager instanceof ClassLoaderLogManager) {
            ((ClassLoaderLogManager) logManager).shutdown();
        }
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:19,代碼來源:Catalina.java

示例14: testLoadingMain

import java.util.logging.LogManager; //導入依賴的package包/類
public static void testLoadingMain() {
    Bridge.desactivate();

    Logger bar = new Bridge.CustomLogger("com.foo.Bar");
    LogManager.getLogManager().addLogger(bar);
    assertNotNull(bar.getParent());
    testParent(bar);
    testParent(LogManager.getLogManager().getLogger("global"));
    testParent(LogManager.getLogManager().getLogger(bar.getName()));

    Bridge.changeContext();

    Logger foo = new Bridge.CustomLogger("com.foo.Foo");
    boolean b = LogManager.getLogManager().addLogger(foo);
    assertEquals(Boolean.TRUE, Boolean.valueOf(b));
    assertNotNull(foo.getParent());
    testParent(foo);
    testParent(LogManager.getLogManager().getLogger("global"));
    testParent(LogManager.getLogManager().getLogger(foo.getName()));

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:TestAppletLoggerContext.java

示例15: getPattern

import java.util.logging.LogManager; //導入依賴的package包/類
private static String getPattern() {
    LogManager manager = LogManager.getLogManager();

    String cname = FileHandler.class.getName();

    String pattern = manager.getProperty(cname + ".pattern");
    if (pattern == null) {
        pattern = "%h/java%u.log";
    }

    return pattern;
}
 
開發者ID:Hitachi-Data-Systems,項目名稱:Open-DM,代碼行數:13,代碼來源:FileHandler.java


注:本文中的java.util.logging.LogManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。