當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。