List of usage examples for java.util.logging LogManager addLogger
public boolean addLogger(Logger logger)
From source file:Main.java
public static void main(String args[]) throws Exception { LogManager lm = LogManager.getLogManager(); Logger logger;//from w w w . j ava 2 s .com FileHandler fh = new FileHandler("log_test.txt"); logger = Logger.getLogger("LoggingExample1"); lm.addLogger(logger); logger.setLevel(Level.INFO); fh.setFormatter(new XMLFormatter()); logger.addHandler(fh); //logger.setUseParentHandlers(false); logger.log(Level.INFO, "test 1"); logger.log(Level.INFO, "test 2"); logger.log(Level.INFO, "test 3"); fh.close(); }
From source file:LoggingExample1.java
public static void main(String args[]) { try {//from www . java 2 s . c om LogManager lm = LogManager.getLogManager(); Logger logger; FileHandler fh = new FileHandler("log_test.txt"); logger = Logger.getLogger("LoggingExample1"); lm.addLogger(logger); logger.setLevel(Level.INFO); fh.setFormatter(new XMLFormatter()); logger.addHandler(fh); //logger.setUseParentHandlers(false); logger.log(Level.INFO, "test 1"); logger.log(Level.INFO, "test 2"); logger.log(Level.INFO, "test 3"); fh.close(); } catch (Exception e) { System.out.println("Exception thrown: " + e); e.printStackTrace(); } }
From source file:HTMLFormatter.java
public static void main(String args[]) throws Exception { LogManager lm = LogManager.getLogManager(); Logger parentLogger, childLogger; FileHandler xml_handler = new FileHandler("log_output.xml"); FileHandler html_handler = new FileHandler("log_output.html"); parentLogger = Logger.getLogger("ParentLogger"); childLogger = Logger.getLogger("ParentLogger.ChildLogger"); lm.addLogger(parentLogger); lm.addLogger(childLogger);// w w w. j a va2 s . co m parentLogger.setLevel(Level.WARNING); childLogger.setLevel(Level.ALL); xml_handler.setFormatter(new XMLFormatter()); html_handler.setFormatter(new HTMLFormatter()); parentLogger.addHandler(xml_handler); childLogger.addHandler(html_handler); childLogger.log(Level.FINE, "This is a fine log message"); childLogger.log(Level.SEVERE, "This is a severe log message"); xml_handler.close(); html_handler.close(); }
From source file:alma.acs.logging.AcsLogger.java
/** * Non-standard factory method to be used only for special offline or testing purposes * where typically an AcsLogger must be provided by an alternative implementation of ContainerServices. * The returned AcsLogger is just like a JDK Logger obtained from {@link Logger#getLogger(String, String)}. * <p>/* www . j a v a 2 s . c o m*/ * Note that we do not supply a {@link LogConfig} and therefore the new AcsLogger cannot register itself * for initial configuration or later configuration change notifications. <br> * <b>It is the client's responsibility to configure the log level and parent logger of the returned AcsLogger!</b> * * @param name the logger's name * @param resourceBundleName * @return <code>AcsLogger</code> that is as close to a normal JDK Logger as possible. * @throws IllegalArgumentException * If a Logger of the given <code>name</code> exists but is not an <code>AcsLogger</code>, * or if an AcsLogger of the given <code>name</code> exists but has a different <code>resourceBundleName</code>. */ public static AcsLogger createUnconfiguredLogger(String name, String resourceBundleName) { // the following code is copied and modified from Logger.getLogger LogManager manager = LogManager.getLogManager(); Logger jdkLogger = manager.getLogger(name); if (jdkLogger != null && !(jdkLogger instanceof AcsLogger)) { throw new IllegalArgumentException( "Logger " + name + " already exists but is not of subtype AcsLogger."); } AcsLogger result = (AcsLogger) jdkLogger; if (result == null) { // Create a new logger. // Note: we may get a MissingResourceException here. result = new AcsLogger(name, resourceBundleName, null, true, null); manager.addLogger(result); result = (AcsLogger) manager.getLogger(name); } // unlike in the JDK logger, we can't fix the resource bundle name if the logger from cache had null and now one is given. // however we check that the old and new bundle are consistent. if (result.getResourceBundleName() != null && !result.getResourceBundleName().equals(resourceBundleName)) { throw new IllegalArgumentException(result.getResourceBundleName() + " != " + resourceBundleName); } return result; }
From source file:org.ebayopensource.turmeric.eclipse.core.logging.SOALogger.java
/** * If the tracing is enabled, then the logging level will be setup accordingly. * * @param clazz the clazz/*from www.j a v a 2s . co m*/ * @return An instance of <code>LogManager</code> */ public static synchronized SOALogger getLogger(String clazz) { java.util.logging.LogManager manager = java.util.logging.LogManager.getLogManager(); Logger result = manager.getLogger(clazz); if (result instanceof SOALogger) { return (SOALogger) result; } else if (result != null) {//there is an existing logger instance if (loggers.keySet().contains(clazz)) { return loggers.get(clazz); } SOALogger logger = new SOALogger(clazz); logger.setLevel(result.getLevel()); logger.setFilter(result.getFilter()); logger.setParent(result.getParent()); logger.setUseParentHandlers(logger.getUseParentHandlers()); loggers.put(clazz, logger); return logger; } else {//can not find a logger, so let's create one. result = new SOALogger(clazz); } manager.addLogger(result); SOALogger logger = (SOALogger) manager.getLogger(clazz); try { ISOALoggingSystemProvider logSystemProvider = SOALoggingSystemExtensionRegistry.getInstance() .getLoggingSystemIDProvider(PluginLogDelegateHandler.getBuildSystemName()); if (logSystemProvider != null) { logSystemProvider.newLoggerCreated(logger); } } catch (Exception e) { //ignore the issue e.printStackTrace(); } return logger; }