当前位置: 首页>>代码示例>>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;未经允许,请勿转载。