当前位置: 首页>>代码示例>>Java>>正文


Java Logger.addHandler方法代码示例

本文整理汇总了Java中java.util.logging.Logger.addHandler方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.addHandler方法的具体用法?Java Logger.addHandler怎么用?Java Logger.addHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.logging.Logger的用法示例。


在下文中一共展示了Logger.addHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testOverridenGetTargetNames

import java.util.logging.Logger; //导入方法依赖的package包/类
@Test
public void testOverridenGetTargetNames() throws Exception {
    assertNotNull(ap);
    final Logger log = Logger.getLogger(ActionProviderSupport.class.getName());
    final Level origLevel = log.getLevel();
    final MockHandler handler = new MockHandler();
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SwingUtilities.invokeAndWait(() -> {
            ap.invokeAction(ActionProvider.COMMAND_CLEAN, Lookup.EMPTY);
        });
        assertEquals("1", handler.props.get("a"));      //NOI18N
        assertEquals("2", handler.props.get("b"));      //NOI18N
    } finally {
        log.setLevel(origLevel);
        log.removeHandler(handler);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:BaseActionProviderTest.java

示例2: tearDown

import java.util.logging.Logger; //导入方法依赖的package包/类
@Override
protected void tearDown() throws Exception {
    final TestHandler handler = new TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
    try {
        logger.setLevel (Level.FINEST);
        logger.addHandler(handler);
        for(String id : registeredClasspaths.keySet()) {
            final Map<ClassPath,Void> classpaths = registeredClasspaths.get(id);
            GlobalPathRegistry.getDefault().unregister(id, classpaths.keySet().toArray(new ClassPath[classpaths.size()]));
        }
        handler.await();
    } finally {
        logger.removeHandler(handler);
    }
    super.tearDown();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ScanStartedTest.java

示例3: tearDown

import java.util.logging.Logger; //导入方法依赖的package包/类
@Override
protected void tearDown() throws Exception {
    final TestHandler handler = new TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
    try {
        logger.setLevel (Level.FINEST);
        logger.addHandler(handler);
        for(String id : registeredClasspaths.keySet()) {
            final Map<ClassPath,Void> classpaths = registeredClasspaths.get(id);
            GlobalPathRegistry.getDefault().unregister(id, classpaths.keySet().toArray(new ClassPath[classpaths.size()]));
        }
        handler.await();
    } finally {
        logger.removeHandler(handler);
    }
    super.tearDown();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:RepositoryUpdaterTest.java

示例4: addDefaultConsoleHandler

import java.util.logging.Logger; //导入方法依赖的package包/类
private static void addDefaultConsoleHandler(Logger logger, String errorMessage,
    String logFilePath) {
  ConsoleHandler consoleHandler = new ConsoleHandler();
  consoleHandler.setFormatter(new GemFireFormatter());
  logger.addHandler(consoleHandler);

  System.err
      .println("ERROR: Could not log to file: " + logFilePath + ". Reason: " + errorMessage);
  System.err.println("Logs will be written on Console.");
  try {
    Thread.sleep(3000); // sleep for 3 secs for the message to appear
  } catch (InterruptedException ignore) {
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:15,代码来源:LogWrapper.java

示例5: tearDown

import java.util.logging.Logger; //导入方法依赖的package包/类
@Override
protected void tearDown() throws Exception {
    final RepositoryUpdaterTest.TestHandler handler = new RepositoryUpdaterTest.TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
    try {
        logger.setLevel (Level.FINEST);
        logger.addHandler(handler);
        for(String id : registeredClasspaths.keySet()) {
            final Map<ClassPath,Void> classpaths = registeredClasspaths.get(id);
            GlobalPathRegistry.getDefault().unregister(id, classpaths.keySet().toArray(new ClassPath[classpaths.size()]));
        }
        handler.await();
    } finally {
        logger.removeHandler(handler);
    }
    super.tearDown();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:IndexingSupportACIDTest.java

示例6: testSkipFoldersBug196702

import java.util.logging.Logger; //导入方法依赖的package包/类
/**
 * It seems that cache.listFiles and cache.containsFiles called getStatus also on folders. Because folders are usually up-to-date (git does not track them),
 * this results in unnecessary call to getOwner, ignore logic or sharability.
 */
public void testSkipFoldersBug196702 () throws Exception {
    final File f1 = new File(repositoryLocation, "1");
    final File f2 = new File(f1, "2");
    final File f3 = new File(f2, "3");
    f3.mkdirs();
    File f = new File(f3, "f");
    f.createNewFile();
    
    FileStatusCache cache = getCache();
    cache.refreshAllRoots(Collections.<File, Collection<File>>singletonMap(repositoryLocation, Collections.singleton(f1)));
    Logger log = Logger.getLogger("org.netbeans.modules.git.status.cache");
    final boolean[] flags = new boolean[1];
    log.addHandler(new Handler() {
        @Override
        public void publish (LogRecord record) {
            if (record.getMessage().startsWith("getCachedStatus for file {0}:")) {
                if (Arrays.asList(f1, f2, f3).contains((File) record.getParameters()[0])) {
                    flags[0] = true;
                }
            }
        }

        @Override
        public void flush () { }

        @Override
        public void close () throws SecurityException { }
    });
    
    Collection<File> newFiles = Arrays.asList(cache.listFiles(new File[] { f1 }, EnumSet.of(FileInformation.Status.NEW_INDEX_WORKING_TREE)));
    assertEquals(Arrays.asList(f), newFiles);
    assertFalse(flags[0]);
    flags[0] = false;
    assertTrue(cache.containsFiles(Collections.singleton(f1), EnumSet.of(FileInformation.Status.NEW_INDEX_WORKING_TREE), true));
    assertFalse(flags[0]);
    assertFalse(cache.containsFiles(Collections.singleton(f1), EnumSet.of(FileInformation.Status.MODIFIED_INDEX_WORKING_TREE), true));
    assertFalse(flags[0]);
    
    // test we do not break anything with the bugfix: ignored files/folders should be recognized even without getStatus call
    SystemAction.get(IgnoreAction.class).performAction(VCSContext.forNodes(new Node[] { new AbstractNode(Children.LEAF, Lookups.fixed(f1)) }));
    flags[0] = false;
    Collection<File> ignoredFiles = Arrays.asList(cache.listFiles(new File[] { f1 }, EnumSet.of(FileInformation.Status.NOTVERSIONED_EXCLUDED)));
    assertEquals(Arrays.asList(f1), ignoredFiles);
    assertFalse(flags[0]);
    flags[0] = false;
    assertTrue(cache.containsFiles(Collections.singleton(f1), EnumSet.of(FileInformation.Status.NOTVERSIONED_EXCLUDED), true));
    assertFalse(flags[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:StatusTest.java

示例7: attachCacheLogHandler

import java.util.logging.Logger; //导入方法依赖的package包/类
private void attachCacheLogHandler(NestedReposLogHandler handler) throws Exception {
    Field f = null;
    try {
        f = FileStatusCache.class.getDeclaredField("LOG");
    } catch (Exception ex) {
        throw ex;
    }
    f.setAccessible(true);
    Logger log = (Logger) f.get(getCache());
    log.addHandler(handler);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:FileStatusCacheTest.java

示例8: setUp

import java.util.logging.Logger; //导入方法依赖的package包/类
@BeforeMethod
@Override
public void setUp() {
    Logger logger = Logger.getLogger("jdk.jshell.execution");
    logger.setLevel(Level.ALL);
    hndlr = new LogTestHandler();
    logger.addHandler(hndlr);
    logged = new HashMap<>();
    Compiler compiler = new Compiler();
    Path modDir = Paths.get("mod");
    compiler.compile(modDir,
            "package my.provide; import java.util.Map;\n" +
            "import jdk.jshell.spi.ExecutionControl;\n" +
            "import jdk.jshell.spi.ExecutionControlProvider;\n" +
            "import jdk.jshell.spi.ExecutionEnv;\n" +
            "public class AlwaysFailingProvider implements ExecutionControlProvider {\n" +
            "    @Override\n" +
            "    public String name() {\n" +
            "        return \"alwaysFailing\";\n" +
            "    }\n" +
            "    @Override\n" +
            "    public ExecutionControl generate(ExecutionEnv env, Map<String, String> parameters) throws Throwable {\n" +
            "        throw new UnsupportedOperationException(\"This operation intentionally broken.\");\n" +
            "    }\n" +
            "}\n",
            "module my.provide {\n" +
            "    requires transitive jdk.jshell;\n" +
            "    provides jdk.jshell.spi.ExecutionControlProvider\n" +
            "        with my.provide.AlwaysFailingProvider;\n" +
            " }");
    Path modPath = compiler.getPath(modDir);
    ccl = createAndRunFromModule("my.provide", modPath);

    provider = new FailOverExecutionControlProvider();
    Map<String, String> pm = provider.defaultParameters();
    pm.put("0", "alwaysFailing");
    pm.put("1", "alwaysFailing");
    pm.put("2", "jdi");
    setUp(builder -> builder.executionEngine(provider, pm));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:FailOverDirectExecutionControlTest.java

示例9: ScanMonitor

import java.util.logging.Logger; //导入方法依赖的package包/类
private ScanMonitor() {
    Logger logger = Logger.getLogger("org.netbeans.modules.java.source.usages.RepositoryUpdater.activity"); //NOI18N
    logger.setLevel(Level.FINEST);
    logger.setUseParentHandlers(false);
    logger.addHandler( new Handler() { //NOI18N

        @Override
        public void publish(LogRecord record) {
            if( Level.FINEST.equals( record.getLevel() )
                    && "START".equals(record.getMessage()) ) { //NOI18N
                lock();
                return;
            }

            if( Level.FINEST.equals( record.getLevel() )
                    && "FINISHED".equals(record.getMessage()) ) { //NOI18N
                unlock();
                return;
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:ScanMonitor.java

示例10: testIncludesChanges

import java.util.logging.Logger; //导入方法依赖的package包/类
public void testIncludesChanges() throws Exception {
    //Prepare
    final TestHandler handler = new TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
    logger.setLevel (Level.FINEST);
    logger.addHandler(handler);
    MutableFilteringResourceImpl r = new MutableFilteringResourceImpl(srcRootWithFiles1.toURL());
    ClassPath cp1 = ClassPathSupport.createClassPath(Collections.singletonList(r));
    ClassPathProviderImpl.register(srcRootWithFiles1, SOURCES, cp1);
    globalPathRegistry_register(SOURCES,new ClassPath[]{cp1});
    assertTrue (handler.await());

    //exclude a file:
    indexerFactory.indexer.setExpectedFile(new URL[0], new URL[] {f1.toURL()}, new URL[0]);
    r.setExcludes(".*/a\\.foo");

    indexerFactory.indexer.awaitDeleted(TIME);
    indexerFactory.indexer.awaitIndex(TIME);

    assertEquals(1, indexerFactory.indexer.deletedCounter);
    assertEquals(Collections.emptySet(), indexerFactory.indexer.expectedDeleted);
    assertEquals(0, indexerFactory.indexer.indexCounter);

    //include the file back:
    indexerFactory.indexer.setExpectedFile(new URL[] {f1.toURL()}, new URL[0], new URL[0]);
    r.setExcludes();

    indexerFactory.indexer.awaitDeleted(TIME);
    indexerFactory.indexer.awaitIndex(TIME);

    assertEquals(0, indexerFactory.indexer.deletedCounter);
    assertEquals(1, indexerFactory.indexer.indexCounter);
    assertEquals(Collections.emptySet(), indexerFactory.indexer.expectedIndex);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:RepositoryUpdaterTest.java

示例11: setUp

import java.util.logging.Logger; //导入方法依赖的package包/类
@Override
protected void setUp() throws java.lang.Exception {
    clearWorkDir();
    // Set up the default lookup, repository, etc.
    EditorTestLookup.setLookup(new String[0], getWorkDir(), new Object[] {},
        getClass().getClassLoader()
    );
    handler = new TestHandler();
    final Logger log = Logger.getLogger(MimePathLookup.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:MimePathLookupTest.java

示例12: testDeadlock208663

import java.util.logging.Logger; //导入方法依赖的package包/类
public void testDeadlock208663() throws Exception {
    CompileTuple ct = files.iterator().next();
    final FileObject fo = URLMapper.findFileObject(ct.indexable.getURL());
    final FileLock lck = fo.lock();
    try {
        final OutputStream out = new BufferedOutputStream(fo.getOutputStream(lck));
        try {
            for (int i = 0; i<101; i++) {
                out.write('a');
            }
        } finally {
            out.close();
        }
    } finally {
        lck.releaseLock();
    }
    
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    JavaIndexerWorker.BUFFER_SIZE = 100;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            ct = pf.next();
            assertNotNull(getCache(ct.jfo));
            got.offer(ct);
            pf.remove();
            assertNull(getCache(ct.jfo));
        }
        assertCollectionsEqual(files,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:SourcePrefetcherTest.java

示例13: testDeletedFile

import java.util.logging.Logger; //导入方法依赖的package包/类
public void testDeletedFile() throws Exception {
    CompileTuple ct = files.iterator().next();
    final FileObject fo = URLMapper.findFileObject(ct.indexable.getURL());        
    fo.delete();
    
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            ct = pf.next();
            try {
                if (ct != null) {
                    assertNotNull(getCache(ct.jfo));
                    got.offer(ct);
                }
            } finally {
                pf.remove();
            }
            if (ct != null) {
                assertNull(getCache(ct.jfo));
            }
        }
        final List<CompileTuple> allButFirst = new LinkedList<CompileTuple>(files);
        allButFirst.remove(0);
        assertCollectionsEqual(allButFirst,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:SourcePrefetcherTest.java

示例14: testStoreUserDefinedResolver

import java.util.logging.Logger; //导入方法依赖的package包/类
/**
 * Bug 240518 - org.openide.filesystems.FileAlreadyLockedException:
 * Services/MIMEResolver/user-defined-mime-resolver.xml.
 *
 * @throws InterruptedException
 */
public void testStoreUserDefinedResolver() throws InterruptedException {
    final Logger mimeResLog = Logger.getLogger(
            MIMEResolverImpl.class.getName());
    final Map<String, Set<String>> mimeToExtensions
            = new HashMap<String, Set<String>>();
    final Throwable[] throwable = new Throwable[1];
    mimeToExtensions.put("text/plan", Collections.singleton("log"));

    Runnable r = new Runnable() {
        @Override
        public void run() {
            MIMEResolverImpl.storeUserDefinedResolver(mimeToExtensions);
        }
    };

    Handler h = new Handler() {

        @Override
        public void publish(LogRecord record) {
            String msg = record.getMessage();
            if (msg != null && msg.startsWith("Cannot delete resolver ")) {
                throwable[0] = record.getThrown();
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    };

    mimeResLog.addHandler(h);
    try {
        // run now to initialize the file
        r.run();

        // run twice in parallel.
        for (int i = 0; i < 10; i++) {
            Thread t1 = new Thread(r, "T1");
            Thread t2 = new Thread(r, "T2");
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            assertNull("No error should occur", throwable[0]);
        }
    } finally {
        mimeResLog.removeHandler(h);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:60,代码来源:MIMEResolverImplTest.java

示例15: 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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:52,代码来源:TestAnonymousLogger.java


注:本文中的java.util.logging.Logger.addHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。