本文整理汇总了Java中java.util.logging.Logger.getUseParentHandlers方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.getUseParentHandlers方法的具体用法?Java Logger.getUseParentHandlers怎么用?Java Logger.getUseParentHandlers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.Logger
的用法示例。
在下文中一共展示了Logger.getUseParentHandlers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reset
import java.util.logging.Logger; //导入方法依赖的package包/类
public void reset() {
// Reset system properties.
System.setProperties(null);
// From "L" release onwards, calling System.setProperties(null) clears the java.io.tmpdir,
// so we set it again. No-op on earlier releases.
System.setProperty("java.io.tmpdir", tmpDir);
if (JAVA_RUNTIME_VERSION != null) {
System.setProperty("java.runtime.version", JAVA_RUNTIME_VERSION);
}
if (JAVA_VM_INFO != null) {
System.setProperty("java.vm.info", JAVA_VM_INFO);
}
if (JAVA_VM_VERSION != null) {
System.setProperty("java.vm.version", JAVA_VM_VERSION);
}
if (JAVA_VM_VENDOR != null) {
System.setProperty("java.vm.vendor", JAVA_VM_VENDOR);
}
if (JAVA_VM_NAME != null) {
System.setProperty("java.vm.name", JAVA_VM_NAME);
}
// Require writable java.home and user.dir directories for preferences
if ("Dalvik".equals(System.getProperty("java.vm.name"))) {
String javaHome = tmpDir + "/java.home";
IoUtils.safeMkdirs(new File(javaHome));
System.setProperty("java.home", javaHome);
}
String userHome = System.getProperty("user.home");
if (userHome.length() == 0) {
userHome = tmpDir + "/user.home";
IoUtils.safeMkdirs(new File(userHome));
System.setProperty("user.home", userHome);
}
// Localization
Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
// Preferences
// Temporarily silence the java.util.prefs logger, which otherwise emits
// an unactionable warning. See RI bug 4751540.
Logger loggerToMute = Logger.getLogger("java.util.prefs");
boolean usedParentHandlers = loggerToMute.getUseParentHandlers();
loggerToMute.setUseParentHandlers(false);
try {
// resetPreferences(Preferences.systemRoot());
resetPreferences(Preferences.userRoot());
} finally {
loggerToMute.setUseParentHandlers(usedParentHandlers);
}
// HttpURLConnection
Authenticator.setDefault(null);
CookieHandler.setDefault(null);
ResponseCache.setDefault(null);
HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);
// Logging
LogManager.getLogManager().reset();
Logger.getLogger("").addHandler(new ConsoleHandler());
// Cleanup to force CloseGuard warnings etc
System.gc();
System.runFinalization();
}
示例2: 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());
}
}