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


Java Logger.getParent方法代碼示例

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


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

示例1: initLogging

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void initLogging(boolean time) {
	
	Logger log = Logger.getAnonymousLogger();
	while (log != null) {
		for (Handler handler : log.getHandlers()) {
			log.removeHandler(handler);
		}
		if (log.getParent() == null) {
			if (time) {
				log.addHandler(new TimeLogHandler());
			} else {
				log.addHandler(new SimpleLogHandler());
			}
		}
		log = log.getParent();
	}		
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:18,代碼來源:SimpleLogging.java

示例2: addConsoleLogging

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void addConsoleLogging() {
	Logger log = Logger.getAnonymousLogger();
	while (log != null) {
		if (log.getParent() == null) {
			log.addHandler(new Handler() {
				
				@Override
				public void close() throws SecurityException {
				}

				@Override
				public void flush() {
				}

				@Override
				public void publish(LogRecord record) {
					System.out.println("[" + record.getLevel() + "] " + record.getMessage());
				}
				
			});
		}
		log = log.getParent();
	}	
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:25,代碼來源:SimpleLogging.java

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

示例4: getVerbosity

import java.util.logging.Logger; //導入方法依賴的package包/類
private static int getVerbosity(Logger logger) throws ProcessingException {
	Level level = null;
	do {
		if (logger == null) {
			processingException("logger is null");
		}
		level = logger.getLevel();
		logger = logger.getParent();
	}
	while (level == null);
	int levelValue = level.intValue();
	if (levelValue == Level.SEVERE.intValue()) {
		return 0;
	}
	if (levelValue == Level.WARNING.intValue()) {
		return 1;
	}
	if (levelValue == Level.INFO.intValue()) {
		return 2;
	}
	return 3;
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:23,代碼來源:AbstractAlvisRE.java

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

示例6: addFileLogging

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void addFileLogging(final String pathToFile) {
	Logger log = Logger.getAnonymousLogger();
	
	
	try {
		final PrintWriter writer = new PrintWriter(new FileWriter(new File(pathToFile)));
		
		while (log != null) {
			if (log.getParent() == null) {
				log.addHandler(new Handler() {
					
					@Override
					public void close() throws SecurityException {
						writer.close();
					}

					@Override
					public void flush() {
						writer.flush();
					}

					@Override
					public void publish(LogRecord record) {
						writer.println("[" + record.getLevel() + "] " + record.getMessage());
					}
					
				});
			}
			log = log.getParent();
		}	
		
	} catch (IOException e) {
		throw new RuntimeException("Could not open file " + new File(pathToFile).getAbsolutePath() + " for logging!", e);
	}
	
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:37,代碼來源:SimpleLogging.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: debugLogger

import java.util.logging.Logger; //導入方法依賴的package包/類
static void debugLogger(Logger logger, Logger expectedParent, TestHandler handler) {
    final String logName = logger.getName();
    final String prefix = "    " + logName;
    System.err.println("Logger " + logName
            + " logged with bundle name " + handler.lastBundleName
            + " (" + handler.lastBundle + ")");
    System.err.println(prefix + ".getResourceBundleName() is "
            + logger.getResourceBundleName());
    System.err.println(prefix + ".getResourceBundle() is "
            + logger.getResourceBundle());
    final Logger parent = logger.getParent();
    final String pname = parent == null ? null : parent.getName();
    final String pclass = parent == null ? ""
            : ("(" + parent.getClass().getName() + ")");
    final String presn = parent == null ? null
            : parent.getResourceBundleName();
    final ResourceBundle pres = parent == null ? null
            : parent.getResourceBundle();
    System.err.println(prefix + ".getParent() is "
            + pname + (pname == null ? ""
                    : (" " + pclass + ": " + parent)));
    System.err.println("    expected parent is :" + expectedParent);
    System.err.println(prefix + ".parent.getResourceBundleName() is "
            + presn);
    System.err.println(prefix + ".parent.getResourceBundle() is "
            + pres);
    System.err.println("    expected parent getResourceBundleName() is "
            + expectedParent.getResourceBundleName());
    System.err.println("    expected parent.getResourceBundle() is "
            + expectedParent.getResourceBundle());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:32,代碼來源:TestSetResourceBundle.java

示例9: main

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
    System.out.println("Creating loggers.");

    // These loggers will be created in the default user context.
    final Logger foo1 = Logger.getLogger( "foo" );
    final Logger bar1 = Logger.getLogger( "foo.bar" );
    if (bar1.getParent() != foo1) {
        throw new RuntimeException("Parent logger of bar1 "+bar1+" is not "+foo1);
    }
    System.out.println("bar1.getParent() is the same as foo1");

    // Set a security manager
    System.setSecurityManager(new SecurityManager());
    System.out.println("Now running with security manager");

    // Triggers the creation of the main AppContext
    ByteArrayInputStream is = new ByteArrayInputStream(new byte[] { 0, 1 });
    ImageIO.read(is); // triggers calls to system loggers & creation of main AppContext

    // verify that we're still using the default user context
    final Logger bar2 = Logger.getLogger( "foo.bar" );
    if (bar1 != bar2) {
        throw new RuntimeException("bar2 "+bar2+" is not the same as bar1 "+bar1);
    }
    System.out.println("bar2 is the same as bar1");
    if (bar2.getParent() != foo1) {
        throw new RuntimeException("Parent logger of bar2 "+bar2+" is not foo1 "+foo1);
    }
    System.out.println("bar2.getParent() is the same as foo1");
    final Logger foo2 = Logger.getLogger("foo");
    if (foo1 != foo2) {
        throw new RuntimeException("foo2 "+foo2+" is not the same as foo1 "+foo1);
    }
    System.out.println("foo2 is the same as foo1");

    System.out.println("Test passed.");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:38,代碼來源:TestLoggingWithMainAppContext.java

示例10: testParent

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void testParent(Logger logger) {
    Logger l = logger;
    while (l.getParent() != null) {
        l = l.getParent();
    }
    assertEquals("", l.getName());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:TestAppletLoggerContext.java

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

示例12: setParentFor

import java.util.logging.Logger; //導入方法依賴的package包/類
public void setParentFor(Logger otherLogger) {
  if (otherLogger.getParent() != logger) {
    otherLogger.setParent(logger);
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:6,代碼來源:LogWrapper.java


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