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


Java Logger.getHandlers方法代碼示例

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


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

示例1: unitLogging

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void unitLogging()
{
    // Start with a fresh root set at warning
    Logger root = LogManager.getLogManager().getLogger("");
    root.setLevel(Level.WARNING);
    for(Handler handler : root.getHandlers()) { root.removeHandler(handler); }

    //Logger.getLogger("java.util.prefs").setLevel(Level.SEVERE);
    Logger.getLogger("org.postgresql.jdbc").setLevel(Level.OFF);
    Logger.getLogger("org.postgresql.Driver").setLevel(Level.OFF);
    Logger.getLogger("org.wwscc").setLevel(Level.ALL);
    
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(Level.ALL);
    ch.setFormatter(new SingleLineFormatter());
    root.addHandler(ch);
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:18,代碼來源:AppSetup.java

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

示例3: setHandlers

import java.util.logging.Logger; //導入方法依賴的package包/類
private void setHandlers(Logger logger, File file) throws FileNotFoundException {
  	for (Handler h : logger.getHandlers()) {
  		logger.removeHandler(h);
  	}
      Handler stderrHandler = new FlushedStreamHandler(System.err, noColors ? CommandLineLogFormatter.INSTANCE : CommandLineLogFormatter.COLORS);
      logger.addHandler(stderrHandler);
      if (file == null)
	stderrHandler.setLevel(logLevel);
else {
	File dir = file.getParentFile();
	if (dir != null) {
		dir.mkdirs();
	}
          Handler fileHandler = new FlushedStreamHandler(new FileOutputStream(file, appendToLog), CommandLineLogFormatter.INSTANCE);
          logger.addHandler(fileHandler);
          if (logLevel.intValue() < Level.FINE.intValue()) {
              fileHandler.setLevel(logLevel);
              stderrHandler.setLevel(Level.FINE);
          }
          else {
              fileHandler.setLevel(Level.FINE);
              stderrHandler.setLevel(logLevel);
          }
      }
  }
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:26,代碼來源:AbstractAlvisNLP.java

示例4: setDebug

import java.util.logging.Logger; //導入方法依賴的package包/類
public void setDebug(boolean debug)
{
	_debug = debug;
	_consumerClient.setDebug(debug);

	if (!debug)
	{
		final Logger parentLogger = Logger.getAnonymousLogger().getParent();

		// Disable console logger if debug mode not turned on
		for (Handler handler : parentLogger.getHandlers())
		{
			if ( handler instanceof ConsoleHandler )
				parentLogger.removeHandler(handler);
		}
	}
}
 
開發者ID:TR-API-Samples,項目名稱:Example.EMA.Java.SpeedGuide,代碼行數:18,代碼來源:SpeedGuideConsumer.java

示例5: appSetup

import java.util.logging.Logger; //導入方法依賴的package包/類
/**
 * Do some common setup for all applications at startup
 * @param name the application name used for Java logging and database logging
 */
public static void appSetup(String name)
{
    // Set our platform wide L&F 
    System.setProperty("swing.defaultlaf", "javax.swing.plaf.nimbus.NimbusLookAndFeel");
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    defaults.put("Table.gridColor", new Color(140,140,140));
    defaults.put("Table.showGrid", true);
    
    // Set the program name which is used by PostgresqlDatabase to identify the app in logs
    System.setProperty("program.name", name);
    
    // Start with a fresh root set at warning
    Logger root = LogManager.getLogManager().getLogger("");
    Formatter format = new SingleLineFormatter();

    root.setLevel(Level.WARNING);
    for(Handler handler : root.getHandlers()) {
        root.removeHandler(handler);
    }

    // Set prefs levels before windows preference load barfs useless data on the user
    Logger.getLogger("java.util.prefs").setLevel(Level.SEVERE);
    // postgres JDBC spits out a lot of data even though we catch the exception
    Logger.getLogger("org.postgresql.jdbc").setLevel(Level.OFF);
    Logger.getLogger("org.postgresql.Driver").setLevel(Level.OFF);

    // Add console handler if running in debug mode
    if (Prefs.isDebug()) {
        ConsoleHandler ch = new ConsoleHandler();
        ch.setLevel(Level.ALL);
        ch.setFormatter(format);
        root.addHandler(ch);
    }

    // For our own logs, we can set super fine level or info depending on if debug mode and attach dialogs to those
    Logger applog = Logger.getLogger("org.wwscc");
    applog.setLevel(Prefs.isDebug() ? Level.FINEST : Level.INFO);
    applog.addHandler(new AlertHandler());

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            applog.log(Level.WARNING, String.format("\bUncaughtException in %s: %s", t, e), e);
        }});

    try {
        File logdir = Prefs.getLogDirectory().toFile();
        if (!logdir.exists())
            if (!logdir.mkdirs())
                throw new IOException("Can't create log directory " + logdir);
        FileHandler fh = new FileHandler(new File(logdir, name+".%g.log").getAbsolutePath(), 1000000, 10, true);
        fh.setFormatter(format);
        fh.setLevel(Level.ALL);
        root.addHandler(fh);
    } catch (IOException ioe) {
        JOptionPane.showMessageDialog(FocusManager.getCurrentManager().getActiveWindow(),
                "Unable to enable logging to file: " + ioe, "Log Error", JOptionPane.ERROR_MESSAGE);
    }

    // force the initialization of IdGenerator on another thread so app can start now without an odd delay later
    new Thread() {
        public void run() {
            IdGenerator.generateId();
        }
    }.start();
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:71,代碼來源:AppSetup.java

示例6: removeHandlers

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void removeHandlers(Logger log) {
    if (log != null) {
        Handler[] handlers = log.getHandlers();
        for (int i = 0; i < handlers.length; i++) {
            log.removeHandler(handlers[i]);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:TestKit.java

示例7: checkHandlers

import java.util.logging.Logger; //導入方法依賴的package包/類
private static boolean checkHandlers(String msg, Logger logger) {
    Handler[] handlers = logger.getHandlers();
    int n = 0;
    for (Handler h : handlers) {
        if (h instanceof UIHandler && !((UIHandler) h).isExceptionOnly()) {
            n++;
        }
    }
    System.err.println(msg+" Handlers with not exception only = "+n+", logger = "+logger);
    return n == 1;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:AutoSubmitTest.java

示例8: cleanupLogger

import java.util.logging.Logger; //導入方法依賴的package包/類
/**
 * Removed all the handlers of the given {@link Logger} instance.
 *
 * @param logger {@link Logger} to be cleaned up.
 */
private static void cleanupLogger(Logger logger) {
  if (logger != null) {
    Handler[] handlers = logger.getHandlers();
    for (Handler handler : handlers) {
      handler.close();
      logger.removeHandler(handler);
    }
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:15,代碼來源:LogWrapper.java

示例9: closeLogHandlers

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void closeLogHandlers(Logger log) {
	if (DEBUG) {
		for (Handler e: log.getHandlers()) {
			e.close();
		}
	}
}
 
開發者ID:LithiumSR,項目名稱:gw2_launcher,代碼行數:8,代碼來源:Operations.java

示例10: getLogger

import java.util.logging.Logger; //導入方法依賴的package包/類
/**
 * Adds a FileLogHandler to the named logger, if there isn't one already.
 * This can be used repeatedly to acquire the same logger, but doing so would be
 * inefficient.  Use Logger.getLogger after this has installed the handler.
 *
 * @param name Log name.
 * @param logFile Where record the log, may be null.  Multiple logs can safely share the same
 * file.
 */
public static Logger getLogger(String name, File logFile) {
    Logger ret = Logger.getLogger(name);
    FileLogHandler fileLogHandler = FileLogHandler.getHandler(logFile);
    for (Handler handler : ret.getHandlers()) {
        if (handler == fileLogHandler) {
            return ret;
        }
    }
    ret.addHandler(fileLogHandler);
    return ret;
}
 
開發者ID:a-hansen,項目名稱:alog,代碼行數:21,代碼來源:Alog.java

示例11: setRootLoggerLevel

import java.util.logging.Logger; //導入方法依賴的package包/類
/**
 * Overrides the system's root logger level.
 * <p>
 * This is for internal testing and debugging only!
 *
 * @param level the level to use, not null
 */
@Nonnull
public static void setRootLoggerLevel(@Nonnull Level level) {
  Objects.requireNonNull(level);

  Logger rootLogger = Logger.getLogger("");

  for (Handler handler : rootLogger.getHandlers())
    handler.setLevel(Level.FINEST);

  rootLogger.setLevel(level);
}
 
開發者ID:lokalized,項目名稱:lokalized-java,代碼行數:19,代碼來源:LoggingUtils.java

示例12: replaceRootHandler

import java.util.logging.Logger; //導入方法依賴的package包/類
/**
 * Removes existing handlers from the root logger and installs a
 * PrintStreamLogHandler for System.out.
 */
public static void replaceRootHandler() {
    Logger global = Logger.getLogger("");
    for (Handler handler : global.getHandlers()) {
        global.removeHandler(handler);
    }
    global.addHandler(new PrintStreamLogHandler("Root Logger", System.out));
}
 
開發者ID:a-hansen,項目名稱:alog,代碼行數:12,代碼來源:Alog.java

示例13: onApplicationEvent

import java.util.logging.Logger; //導入方法依賴的package包/類
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextRefreshedEvent) {
		Logger log = LogManager.getLogManager().getLogger("");
		for (Handler h : log.getHandlers()) {
		    h.setLevel(Level.INFO);
		}        	
    }
}
 
開發者ID:guilhebl,項目名稱:item-shop-reactive-backend,代碼行數:10,代碼來源:ApplicationListenerBean.java

示例14: setGlobalLevel

import java.util.logging.Logger; //導入方法依賴的package包/類
public static void setGlobalLevel(Level newLevel) {
  Logger rootLogger = LogManager.getLogManager().getLogger("");
  rootLogger.setLevel(newLevel);
  for (Handler h : rootLogger.getHandlers()) {
    h.setLevel(newLevel);
  }
}
 
開發者ID:XDean,項目名稱:Java-EX,代碼行數:8,代碼來源:LogUtil.java

示例15: setHandlers

import java.util.logging.Logger; //導入方法依賴的package包/類
public void setHandlers(Logger logger, Level logLevel) throws FileNotFoundException {
	for (Handler h : logger.getHandlers()) {
		logger.removeHandler(h);
	}
	Handler stderrHandler = new FlushedStreamHandler(System.err, CommandLineLogFormatter.INSTANCE);
	logger.addHandler(stderrHandler);
	stderrHandler.setLevel(logLevel);

	Handler fileHandler = new FlushedStreamHandler(new FileOutputStream(new File(processingDir, ALVISNLP_LOG_FILENAME), false), CommandLineLogFormatter.INSTANCE);
    logger.addHandler(fileHandler);
	fileHandler.setLevel(logLevel);
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:13,代碼來源:Run.java


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