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


Java Logger.getLevel方法代碼示例

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


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

示例1: testRootCache

import java.util.logging.Logger; //導入方法依賴的package包/類
public void testRootCache() throws IOException {
    final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
    final FileObject root1 = FileUtil.createFolder(wd, "root1");
    final FileObject module1 = createTestFile (root1, null, "module-info.java", "module Foo {}");    //NOI18N
    final FileObject java1 = createTestFile (root1, "org/nb/test", "Test.java", "package org.nb.test;\nclass Test {}");    //NOI18N
    final FileObject root2 = FileUtil.createFolder(wd, "root2");
    final FileObject module2 = createTestFile (root2, null, "module-info.java", "module Boo {}");    //NOI18N
    final FileObject java2 = createTestFile (root2, "org/nb/test", "Test2.java", "package org.nb.test;\nclass Test2 {}");    //NOI18N
    final Logger l = Logger.getLogger(DefaultSourceLevelQueryImpl.class.getName());
    final Level origLogLevel = l.getLevel();
    final H h = new H();
    l.setLevel(Level.FINE);
    l.addHandler(h);
    try {
        assertEquals(
                expectedSourceLevel().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        List<? extends FileObject> roots = h.getRoots();
        assertEquals(1, roots.size());
        assertEquals(root1, roots.get(0));
        h.reset();
        assertEquals(
                expectedSourceLevel().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        roots = h.getRoots();
        assertEquals(0, roots.size());
        h.reset();
        assertEquals(
                expectedSourceLevel().toString(),
                SourceLevelQuery.getSourceLevel(java2));
        roots = h.getRoots();
        assertEquals(1, roots.size());
        assertEquals(root2, roots.get(0));
    } finally {
        l.removeHandler(h);
        l.setLevel(origLogLevel);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:DefaultSourceLevelQueryImplTest.java

示例2: testIsModuleCache

import java.util.logging.Logger; //導入方法依賴的package包/類
public void testIsModuleCache() throws IOException {
    final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
    final FileObject root1 = FileUtil.createFolder(wd, "root1");
    final FileObject module1 = createTestFile (root1, null, "module-info.java", "module Foo {}");    //NOI18N
    final FileObject java1 = createTestFile (root1, "org/nb/test", "Test.java", "package org.nb.test;\nclass Test {}");    //NOI18N
    final FileObject root2 = FileUtil.createFolder(wd, "root2");
    final FileObject java2 = createTestFile (root2, "org/nb/test", "Test2.java", "package org.nb.test;\nclass Test2 {}");    //NOI18N
    final Logger l = Logger.getLogger(DefaultSourceLevelQueryImpl.class.getName());
    final Level origLogLevel = l.getLevel();
    final H h = new H();
    l.setLevel(Level.FINE);
    l.addHandler(h);
    try {
        assertEquals(
                expectedSourceLevel().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        List<? extends Boolean> isMods = h.getIsModules();
        assertEquals(1, isMods.size());
        assertEquals(Boolean.TRUE, isMods.get(0));
        h.reset();
        assertEquals(
                expectedSourceLevel().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        isMods = h.getIsModules();
        assertEquals(0, isMods.size());
        h.reset();
        assertEquals(
                JavaPlatform.getDefault().getSpecification().getVersion().toString(),
                SourceLevelQuery.getSourceLevel(java2));
        isMods = h.getIsModules();
        assertEquals(1, isMods.size());
        assertEquals(Boolean.FALSE, isMods.get(0));
    } finally {
        l.removeHandler(h);
        l.setLevel(origLogLevel);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:38,代碼來源:DefaultSourceLevelQueryImplTest.java

示例3: testIsModuleCache_ModuleInfoDeleted

import java.util.logging.Logger; //導入方法依賴的package包/類
public void testIsModuleCache_ModuleInfoDeleted() throws IOException {
    final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
    final FileObject root1 = FileUtil.createFolder(wd, "root1");
    FileObject module1 = createTestFile (root1, null, "module-info.java", "module Foo {}");    //NOI18N
    final FileObject java1 = createTestFile (root1, "org/nb/test", "Test.java", "package org.nb.test;\nclass Test {}");    //NOI18N
    final Logger l = Logger.getLogger(DefaultSourceLevelQueryImpl.class.getName());
    final Level origLogLevel = l.getLevel();
    final H h = new H();
    l.setLevel(Level.FINE);
    l.addHandler(h);
    try {
        assertEquals(
                expectedSourceLevel().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        List<? extends Boolean> isMods = h.getIsModules();
        assertEquals(1, isMods.size());
        assertEquals(Boolean.TRUE, isMods.get(0));
        h.reset();
        module1.delete();
        assertEquals(
                JavaPlatform.getDefault().getSpecification().getVersion().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        isMods = h.getIsModules();
        assertEquals(1, isMods.size());
        assertEquals(Boolean.FALSE, isMods.get(0));
        h.reset();
        assertEquals(
                JavaPlatform.getDefault().getSpecification().getVersion().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        isMods = h.getIsModules();
        assertEquals(0, isMods.size());
    } finally {
        l.removeHandler(h);
        l.setLevel(origLogLevel);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:DefaultSourceLevelQueryImplTest.java

示例4: testIsModuleCache_ModuleInfoCreated

import java.util.logging.Logger; //導入方法依賴的package包/類
public void testIsModuleCache_ModuleInfoCreated() throws IOException {
    final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
    final FileObject root1 = FileUtil.createFolder(wd, "root1");
    final FileObject java1 = createTestFile (root1, "org/nb/test", "Test.java", "package org.nb.test;\nclass Test {}");    //NOI18N
    final Logger l = Logger.getLogger(DefaultSourceLevelQueryImpl.class.getName());
    final Level origLogLevel = l.getLevel();
    final H h = new H();
    l.setLevel(Level.FINE);
    l.addHandler(h);
    try {
        assertEquals(
                JavaPlatform.getDefault().getSpecification().getVersion().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        List<? extends Boolean> isMods = h.getIsModules();
        assertEquals(1, isMods.size());
        assertEquals(Boolean.FALSE, isMods.get(0));
        h.reset();
        FileObject module1 = createTestFile (root1, null, "module-info.java", "module Foo {}");    //NOI18N
        assertEquals(
                expectedSourceLevel().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        isMods = h.getIsModules();
        assertEquals(1, isMods.size());
        assertEquals(Boolean.TRUE, isMods.get(0));
        h.reset();
        assertEquals(
                expectedSourceLevel().toString(),
                SourceLevelQuery.getSourceLevel(java1));
        isMods = h.getIsModules();
        assertEquals(0, isMods.size());
    } finally {
        l.removeHandler(h);
        l.setLevel(origLogLevel);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:DefaultSourceLevelQueryImplTest.java

示例5: testJavaPlatformCaching

import java.util.logging.Logger; //導入方法依賴的package包/類
public void testJavaPlatformCaching() throws IOException {
    FileObject artefact = getSourceFile (FILE_IN_PACKAGE);
    Lookup.getDefault().lookup(MockSLQ.class).register(this.srcRoot, new SpecificationVersion("9"));  //NOI18N
    assertEquals("9", SourceLevelQuery.getSourceLevel(artefact)); //NOI18N
    ClassPathProvider cpp = new DefaultClassPathProvider ();
    final Logger log = Logger.getLogger(DefaultClassPathProvider.class.getName());
    final H h = new H();
    final Level origLevel = log.getLevel();
    log.setLevel(Level.FINE);
    log.addHandler(h);
    try {
        ClassPath cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_BOOT_PATH);
        assertEquals ("DefaultClassPathProvider returned invalid classpath for MODULE_BOOT_PATH with source level 9",
                j9.getBootstrapLibraries(),
                cp);
        List<Optional<JavaPlatform>> plts = h.getCachedPlatforms();
        assertEquals(1, plts.size());
        assertEquals(j9, plts.get(0).get());
        h.reset();
        artefact = getSourceFile (FILE_IN_PACKAGE);
        cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_BOOT_PATH);
        assertEquals ("DefaultClassPathProvider returned invalid classpath for MODULE_BOOT_PATH with source level 9",
                j9.getBootstrapLibraries(),
                cp);
        plts = h.getCachedPlatforms();
        assertEquals(0, plts.size());
    } finally {
        log.removeHandler(h);
        log.setLevel(origLevel);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:DefaultClassPathProviderTest.java

示例6: testLRUCaching

import java.util.logging.Logger; //導入方法依賴的package包/類
public void testLRUCaching() throws IOException {
    FileObject artefact = getSourceFile (FILE_IN_PACKAGE);
    Lookup.getDefault().lookup(MockSLQ.class).register(this.srcRoot, new SpecificationVersion("9"));  //NOI18N
    assertEquals("9", SourceLevelQuery.getSourceLevel(artefact)); //NOI18N
    ClassPathProvider cpp = new DefaultClassPathProvider ();
    final Logger log = Logger.getLogger(DefaultClassPathProvider.class.getName());
    final H h = new H();
    final Level origLevel = log.getLevel();
    log.setLevel(Level.FINE);
    log.addHandler(h);
    try {
        ClassPath cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_BOOT_PATH);
        assertEquals ("DefaultClassPathProvider returned invalid classpath for MODULE_BOOT_PATH with source level 9",
                j9.getBootstrapLibraries(),
                cp);
        List<JavaPlatform> plts = h.getLRU();
        assertEquals(1, plts.size());
        assertEquals(j9, plts.get(0));
        h.reset();
        artefact = getSourceFile (FILE_IN_PACKAGE);
        cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_BOOT_PATH);
        assertEquals ("DefaultClassPathProvider returned invalid classpath for MODULE_BOOT_PATH with source level 9",
                j9.getBootstrapLibraries(),
                cp);
        plts = h.getLRU();
        assertEquals(0, plts.size());
    } finally {
        log.removeHandler(h);
        log.setLevel(origLevel);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:DefaultClassPathProviderTest.java

示例7: getEffectiveLevel

import java.util.logging.Logger; //導入方法依賴的package包/類
public static Level getEffectiveLevel(Logger logger) {
    if(logger.getLevel() != null) {
        return logger.getLevel();
    }

    if(logger.getParent() != null) {
        return getEffectiveLevel(logger.getParent());
    }

    return null;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:12,代碼來源:Logging.java

示例8: main

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:52,代碼來源:TestAnonymousLogger.java

示例9: testDeletedFileDoesNotReturnInputStream

import java.util.logging.Logger; //導入方法依賴的package包/類
public void testDeletedFileDoesNotReturnInputStream() throws Exception {
    final FileObject testFo = FileUtil.createData(root,"testfile.data");
    final File testFile = FileUtil.toFile(testFo);
    final Logger LOGGER = Logger.getLogger(FileObj.class.getName());
    final Handler handler = new Handler() {
        @Override
        public void publish(LogRecord record) {
            if ("FileObj.getInputStream_after_is_valid".equals(record.getMessage())) {
                testFile.delete();
            }
        }
        @Override
        public void flush() {
        }
        @Override
        public void close() throws SecurityException {
        }
    };
    final Level originalLevel = LOGGER.getLevel();
    LOGGER.setLevel(Level.FINEST);
    try {
        LOGGER.addHandler(handler);
        try {
            testFo.getInputStream();
            assertTrue("Exception not thrown by deleted file getInputStream()", false);
        } catch (FileNotFoundException e) {
            //pass - expected exception
        } finally {
            LOGGER.removeHandler(handler);
        }
    } finally {
        LOGGER.setLevel(originalLevel);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:BaseFileObjectTestHid.java

示例10: register

import java.util.logging.Logger; //導入方法依賴的package包/類
static TraceHandler register() {
    final Logger l = Logger.getLogger(ModuleNames.class.getName());
    final Level origLevel = l.getLevel();
    final TraceHandler th = new TraceHandler(l, origLevel);
    l.setLevel(Level.FINE);
    l.addHandler(th);
    return th;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:ModuleNamesTest.java

示例11: levelOf

import java.util.logging.Logger; //導入方法依賴的package包/類
private Level levelOf(Logger log) {
    Level lvl = log.getLevel();
    if (lvl != null) {
        return lvl;
    } else {
        Logger par = log.getParent();
        if (par != null) {
            return levelOf(par);
        } else {
            return Level.INFO;
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:EmbedderFactory.java

示例12: setupLogging

import java.util.logging.Logger; //導入方法依賴的package包/類
private static void setupLogging() {
    // Set logging level to at least WARNING for apache so that it doesn't log auth cookies.
    try {
        Logger apacheLogger = Logger.getLogger("org.apache");
        if (apacheLogger.getLevel() == null
                || apacheLogger.getLevel().intValue() < Level.WARNING.intValue()) {
            apacheLogger.setLevel(Level.WARNING);
        }
    } catch (Exception e) {
        LOG.log(Level.WARNING, "Error setting logger level on apache logger!", e);
    }
}
 
開發者ID:Hitachi-Data-Systems,項目名稱:Open-DM,代碼行數:13,代碼來源:ConfigurationHelper.java

示例13: testEncodingCaching

import java.util.logging.Logger; //導入方法依賴的package包/類
public void testEncodingCaching() throws Exception {
    final Logger log = Logger.getLogger(HtmlDataObject.class.getName());
    class TestHandler extends Handler {
        private final Pattern pattern = Pattern.compile("^HtmlDataObject.getFileEncoding (non)?cached .*$");   //NOI18N
        Boolean cached;
        @Override
        public void publish(LogRecord record) {
            final String message = record.getMessage();
            final Matcher matcher = pattern.matcher(message);
            if (matcher.matches()) {
                cached = matcher.group(1) == null ? Boolean.TRUE : Boolean.FALSE;
            }
        }
        @Override
        public void flush() {
        }
        @Override
        public void close() throws SecurityException {
        }
    }
    final TestHandler handler = new TestHandler();
    log.addHandler(handler);
    final Level origLevel = log.getLevel();
    log.setLevel(Level.FINEST);
    try {
        FileObject data = FileUtil.createData (FileUtil.toFileObject(getWorkDir()), "UTF8.html"); //NOI18N
        copy("UTF8.html",data); //NOI18N
        handler.cached = null;
        read(data);
        assertFalse("Encoding should be calculated",handler.cached);    //NOI18N
        handler.cached = null;
        read(data);
        assertTrue("Encoding should be cached",handler.cached);        //NOI18N
        //Modify file
        copy("UTF8.html",data); //NOI18N
        handler.cached = null;
        read(data);
        assertFalse("Encoding should be calculated",handler.cached);    //NOI18N
        handler.cached = null;
        read(data);
        assertTrue("Encoding should be cached",handler.cached);        //NOI18N
    } finally {
        log.setLevel(origLevel);
        log.removeHandler(handler);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:47,代碼來源:EncodingTest.java

示例14: testRootCache

import java.util.logging.Logger; //導入方法依賴的package包/類
public void testRootCache() {
    Lookup.getDefault().lookup(CPP.class)
            .add(
                    root1,
                    ClassPath.SOURCE,
                    ClassPathSupport.createClassPath(root1))
            .add(
                    root2,
                    ClassPath.SOURCE,
                    ClassPathSupport.createClassPath(root2));
    final Logger l = Logger.getLogger(ModuleOraculum.class.getName());
    final Level origLogLevel = l.getLevel();
    final H h = new H();
    l.setLevel(Level.FINE);
    l.addHandler(h);
    try {
        final ClasspathInfo cpInfo = new ClasspathInfo.Builder(ClassPath.EMPTY).build();
        final JavacParser parser = new JavacParser(Collections.emptyList(), true);
        JavacTaskImpl impl = JavacParser.createJavacTask(
                javaFile1,
                null,
                cpInfo,
                parser,
                null,
                false);
        assertEquals("Test", Options.instance(impl.getContext()).get("-XD-Xmodule:"));    //NOI18N
        List<? extends FileObject> roots = h.getRoots();
        assertEquals(1, roots.size());
        assertEquals(root1, roots.get(0));
        h.reset();
        impl = JavacParser.createJavacTask(
                javaFile1,
                null,
                cpInfo,
                parser,
                null,
                false);
        assertEquals("Test", Options.instance(impl.getContext()).get("-XD-Xmodule:"));    //NOI18N
        roots = h.getRoots();
        assertEquals(0, roots.size());
        impl = JavacParser.createJavacTask(
                javaFile2,
                null,
                cpInfo,
                parser,
                null,
                false);
        assertEquals("Next", Options.instance(impl.getContext()).get("-XD-Xmodule:"));    //NOI18N
        roots = h.getRoots();
        assertEquals(1, roots.size());
        assertEquals(root2, roots.get(0));
    } finally {
        l.removeHandler(h);
        l.setLevel(origLogLevel);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:57,代碼來源:ModuleOraculumTest.java

示例15: disableLogging

import java.util.logging.Logger; //導入方法依賴的package包/類
@BeforeClass
public static void disableLogging() {
    Logger pdfboxLogger = Logger.getLogger("org.apache.pdfbox");
    defaultLogLevel = pdfboxLogger.getLevel();
    pdfboxLogger.setLevel(Level.OFF);
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:7,代碼來源:TestTableDetection.java


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