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


Java Logger.getLogger方法代码示例

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


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

示例1: tearDown

import java.util.logging.Logger; //导入方法依赖的package包/类
@Override
protected void tearDown() throws Exception {
    if (classPathsForTest != null && !classPathsForTest.isEmpty()) {
        Logger logger = Logger.getLogger(RepositoryUpdater.class.getName() + ".tests");
        logger.setLevel(Level.FINEST);
        Waiter w = new Waiter(classPathContainsBinaries());
        logger.addHandler(w);

        for(String cpId : classPathsForTest.keySet()) {
            ClassPath cp = classPathsForTest.get(cpId);
            GlobalPathRegistry.getDefault().unregister(cpId, new ClassPath [] { cp });
        }

        w.waitForScanToFinish();
        logger.removeHandler(w);
    }

    super.tearDown();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:CslTestBase.java

示例2: find

import java.util.logging.Logger; //导入方法依赖的package包/类
public static @Nullable ClassLogger find(@Nullable Logger parent, Class<?> klass, @Nullable String instanceKey) {
    if(parent == null) {
        parent = Logger.getLogger("");
    }

    String name = getName(klass, instanceKey);
    if(parent instanceof ClassLogger && Objects.equals(parent.getName(), name)) {
        // If the given parent logger looks exactly like the logger
        // we are supposed to return, just use it. This makes it easy
        // to replace a parent logger with a child once only e.g.
        //
        //     logger = ClassLogger.get(logger, getClass(), "myInstance")
        return (ClassLogger) parent;
    }

    LogManager lm = LogManager.getLogManager();
    Logger logger = lm.getLogger(name);
    if(logger instanceof ClassLogger) {
        if(parent != logger.getParent()) {
            throw new IllegalStateException("Already registred logger " + name + " has a different parent than the one requested:\n  old = " + logger.getParent() + "\n  new = " + parent);
        }
        return (ClassLogger) logger;
    } else {
        return null;
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:27,代码来源:ClassLogger.java

示例3: testPermission

import java.util.logging.Logger; //导入方法依赖的package包/类
/**
 * Test the LoggingPermission("control") is required.
 * @param loggerName The logger to use.
 */
public static void testPermission(String loggerName) {
    if (System.getSecurityManager() != null) {
        throw new Error("Security manager is already set");
    }
    Policy.setPolicy(new SimplePolicy(TestCase.PERMISSION));
    System.setSecurityManager(new SecurityManager());
    final ResourceBundle bundle = ResourceBundle.getBundle(LIST_BUNDLE_NAME);
    Logger foobar = Logger.getLogger(loggerName);
    try {
        foobar.setResourceBundle(bundle);
        throw new RuntimeException("Permission not checked!");
    } catch (AccessControlException x) {
        if (x.getPermission() instanceof LoggingPermission) {
            if ("control".equals(x.getPermission().getName())) {
                System.out.println("Got expected exception: " + x);
                return;
            }
        }
        throw new RuntimeException("Unexpected exception: "+x, x);
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:TestSetResourceBundle.java

示例4: failToLoadResourceBundle

import java.util.logging.Logger; //导入方法依赖的package包/类
static void failToLoadResourceBundle(String loggerName, String rbName,
        boolean getLoggerInNamedModule, String helpMsg) {
    String msg = String.format(
            "Logger : %s. Expected exception is not thrown for ResourceBundle : %s.",
            loggerName, rbName);
    System.out.println(helpMsg);
    try {
        if(getLoggerInNamedModule) {
            ModuleLoggerAccess.getLogger(loggerName, rbName);
        } else {
            Logger.getLogger(loggerName, rbName);
        }
        throw new RuntimeException(msg);
    } catch (MissingResourceException expected) {
        System.out.println("Get expected exception : " + expected);
        return;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ResourceBundleTest.java

示例5: logLookAndFeelUsage

import java.util.logging.Logger; //导入方法依赖的package包/类
private static void logLookAndFeelUsage() {
    if( lafLogged )
        return;
    lafLogged = true;
    LookAndFeel laf = UIManager.getLookAndFeel();
    Logger logger = Logger.getLogger( "org.netbeans.ui.metrics.laf" );   // NOI18N
    LogRecord rec = new LogRecord( Level.INFO, "USG_LOOK_AND_FEEL" ); //NOI18N
    String lafId = laf.getID();
    if( laf.getDefaults().getBoolean( "nb.dark.theme" ) ) //NOI18N
    {
        lafId = "DARK " + lafId; //NOI18N
    }
    rec.setParameters( new Object[]{ lafId, laf.getName() } );
    rec.setLoggerName( logger.getName() );
    logger.log( rec );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:MainWindow.java

示例6: handleUserFollowed

import java.util.logging.Logger; //导入方法依赖的package包/类
private static void handleUserFollowed(LiveEvent event, JsonObject payload) {
	try {
		if (Files.notExists(Paths.get("payloads\\"))) {
			new File("payloads\\").mkdir();
		}

		Logger logger = Logger.getLogger("payload-userFollowed");
		FileHandler fh = new FileHandler("payloads\\" + logger.getName() + ".json");
		SimpleFormatter formatter = new SimpleFormatter();
		fh.setFormatter(formatter);

		logger.addHandler(fh);

		logger.log(Level.INFO, payload.toString());
	} catch (SecurityException | IOException e) {}
}
 
开发者ID:StreamerSpectrum,项目名称:BeamTeamDiscordBot,代码行数:17,代码来源:ConstellationManager.java

示例7: run

import java.util.logging.Logger; //导入方法依赖的package包/类
public void run() {
    boolean setTCCL = false;
    try {
        if (clToSetOnTCCL != null) {
            Thread.currentThread().setContextClassLoader(clToSetOnTCCL);
            setTCCL = true;
        }
        // this should succeed if the bundle is on the system classpath.
        try {
            Logger aLogger = Logger.getLogger(ResourceBundleSearchTest.newLoggerName(),
                                              bundleName);
            msg = "INFO: LoggingThread.run() found the bundle " + bundleName
                  + (setTCCL ? " with " : " without ") + "setting the TCCL";
            foundBundle = true;
        } catch (MissingResourceException re) {
            msg = "INFO: LoggingThread.run() did not find the bundle " + bundleName
                  + (setTCCL ? " with " : " without ") + "setting the TCCL";
            foundBundle = false;
        }
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:ResourceBundleSearchTest.java

示例8: setUp

import java.util.logging.Logger; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
    LOG = Logger.getLogger("test." + getName());
    try {
        clearWorkDir();
    } catch (IOException ex) {
        LOG.log(Level.WARNING, "Cannot clear work dir for some reason", ex);
    }
    
    File dir = new File(getWorkDir(), "dir");
    dir.mkdir();
    
    for (int i = 0; i < 100; i++) {
        new File(dir, "x" + i + ".txt").createNewFile();
        new File(dir, "d" + i).mkdir();
    }
    
    assertEquals("Two hundred", 200, dir.list().length);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:NoLockWhenRefreshIOTest.java

示例9: 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

示例10: fatalError

import java.util.logging.Logger; //导入方法依赖的package包/类
public void fatalError(SAXParseException exception) throws SAXException {
    if (exception.getMessage().contains("Invalid encoding")) { // NOI18N
        // ok, go on, we want to continue parsing anyway
        return;
    }
    
    // it may be caused by wrong user XML documents, notify only in debug mode
    // also see #16484 if the error message makes no sense
    Logger emgr = Logger.getLogger(XMLMIMEComponent.class.getName());
    if (emgr.isLoggable(Level.FINE)) {
        emgr.fine("[while parsing " + fo + "] " + exception.getSystemId() + ":" + exception.getLineNumber() + ":" + exception.getColumnNumber() + ": " + exception.getMessage()); // NOI18N
    }
    
    // go on anyway, needed to fix 203959
    if (errors++ > 10) {
        state = ERROR;
        throw STOP;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:XMLMIMEComponent.java

示例11: TestLogger

import java.util.logging.Logger; //导入方法依赖的package包/类
public TestLogger(String loggerName, String className) {
    Logger l = null;
    try {
        l = Logger.getLogger(loggerName);
    } catch (Exception x) {
        // OK. Should not happen
    }
    logger = l;
    this.className=className;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TestLogger.java

示例12: run

import java.util.logging.Logger; //导入方法依赖的package包/类
@Override
public void run() {
    System.out.println("Running " + Thread.currentThread().getName());

    for (int i=0; i < MAX_ITERATIONS; i++) {
        logger = Logger.getLogger("DrainFindDeadlockTest"+i);
        DrainFindDeadlockTest.randomDelay();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:DrainFindDeadlockTest.java

示例13: log

import java.util.logging.Logger; //导入方法依赖的package包/类
private static void log(LogRecord[] arr, String loggerName) {
    if (arr == null) {
        return;
    }
    Logger logger = Logger.getLogger(loggerName); // NOI18N
    for (LogRecord r : arr) {
        logger.log(r);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:OpenProjectList.java

示例14: setUp

import java.util.logging.Logger; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
    clearWorkDir();

    LOG = Logger.getLogger("test." + getName());
    Logger.getLogger("org.openide.util.Mutex").setUseParentHandlers(false);

    File dir = new File(getWorkDir(), "test");
    dir.mkdirs();
    testFolder = FileUtil.toFileObject(dir);
    assertNotNull("Test folder created", testFolder);

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:SlowRefreshTest.java

示例15: restored

import java.util.logging.Logger; //导入方法依赖的package包/类
public @Override void restored() {
    if (!ENABLED) {
        return ;
    }
    
    Logger log = Logger.getLogger("TIMER"); // NOI18N
    log.setUseParentHandlers(false);
    log.setLevel(Level.FINE);
    log.addHandler(timers);
    
    EditorRegistry.addPropertyChangeListener(docTracker);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:Install.java


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