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


Java CustomFormatter類代碼示例

本文整理匯總了Java中it.albertus.util.logging.CustomFormatter的典型用法代碼示例。如果您正苦於以下問題:Java CustomFormatter類的具體用法?Java CustomFormatter怎麽用?Java CustomFormatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: enableLoggingFileHandler

import it.albertus.util.logging.CustomFormatter; //導入依賴的package包/類
private void enableLoggingFileHandler() {
	final String loggingPath = getString("logging.files.path", Defaults.LOGGING_FILES_PATH);
	if (loggingPath != null && !loggingPath.isEmpty()) {
		final FileHandlerConfig newConfig = new FileHandlerConfig();
		newConfig.setPattern(loggingPath + File.separator + LOG_FILE_NAME);
		newConfig.setLimit(getInt("logging.files.limit", Defaults.LOGGING_FILES_LIMIT) * 1024);
		newConfig.setCount(getInt("logging.files.count", Defaults.LOGGING_FILES_COUNT));
		newConfig.setAppend(true);
		newConfig.setFormatter(new CustomFormatter(EarthquakeBulletin.LOG_FORMAT));

		if (fileHandler != null) {
			final FileHandlerConfig oldConfig = FileHandlerConfig.fromHandler(fileHandler);
			if (!oldConfig.getPattern().equals(newConfig.getPattern()) || oldConfig.getLimit() != newConfig.getLimit() || oldConfig.getCount() != newConfig.getCount()) {
				logger.log(Level.FINE, "Logging configuration has changed; closing and removing old {0}...", fileHandler.getClass().getSimpleName());
				LoggingSupport.getRootLogger().removeHandler(fileHandler);
				fileHandler.close();
				fileHandler = null;
				logger.log(Level.FINE, "Old FileHandler closed and removed.");
			}
		}

		if (fileHandler == null) {
			logger.log(Level.FINE, "FileHandler not found; creating one...");
			try {
				new File(loggingPath).mkdirs();
				fileHandler = new EnhancedFileHandler(newConfig);
				LoggingSupport.getRootLogger().addHandler(fileHandler);
				logger.log(Level.FINE, "{0} created successfully.", fileHandler.getClass().getSimpleName());
			}
			catch (final IOException ioe) {
				logger.log(Level.SEVERE, ioe.toString(), ioe);
			}
		}
	}
}
 
開發者ID:Albertus82,項目名稱:EarthquakeBulletin,代碼行數:36,代碼來源:EarthquakeBulletinConfig.java

示例2: enableLoggingFileHandler

import it.albertus.util.logging.CustomFormatter; //導入依賴的package包/類
protected void enableLoggingFileHandler() {
	final String fileHandlerPattern = getFileHandlerPattern();
	if (fileHandlerPattern != null && !fileHandlerPattern.isEmpty()) {
		final FileHandlerConfig newConfig = new FileHandlerConfig();
		newConfig.setPattern(fileHandlerPattern);
		newConfig.setLimit(getFileHandlerLimit());
		newConfig.setCount(getFileHandlerCount());
		newConfig.setAppend(true);
		newConfig.setFormatter(new CustomFormatter(getFileHandlerFormat()));

		if (fileHandler != null) {
			final FileHandlerConfig oldConfig = FileHandlerConfig.fromHandler(fileHandler);
			if (!oldConfig.getPattern().equals(newConfig.getPattern()) || oldConfig.getLimit() != newConfig.getLimit() || oldConfig.getCount() != newConfig.getCount()) {
				logger.log(Level.FINE, "Logging configuration has changed; closing and removing old {0}...", fileHandler.getClass().getSimpleName());
				LoggingSupport.getRootLogger().removeHandler(fileHandler);
				fileHandler.close();
				fileHandler = null;
				logger.log(Level.FINE, "Old FileHandler closed and removed.");
			}
		}

		if (fileHandler == null) {
			logger.log(Level.FINE, "FileHandler not found; creating one...");
			try {
				final File logDir = new File(fileHandlerPattern).getParentFile();
				if (logDir != null) {
					logDir.mkdirs();
				}
				fileHandler = new EnhancedFileHandler(newConfig);
				LoggingSupport.getRootLogger().addHandler(fileHandler);
				logger.log(Level.FINE, "{0} created successfully.", fileHandler.getClass().getSimpleName());
			}
			catch (final IOException ioe) {
				logger.log(Level.SEVERE, ioe.toString(), ioe);
			}
		}
	}
}
 
開發者ID:Albertus82,項目名稱:JFaceUtils,代碼行數:39,代碼來源:LoggingConfig.java

示例3: enableLoggingFileHandler

import it.albertus.util.logging.CustomFormatter; //導入依賴的package包/類
private void enableLoggingFileHandler() {
	final String loggingPath = getString("logging.files.path", Defaults.LOGGING_FILES_PATH);
	if (loggingPath != null && !loggingPath.isEmpty()) {
		final TimeBasedRollingFileHandlerConfig newConfig = new TimeBasedRollingFileHandlerConfig();
		newConfig.setFileNamePattern(loggingPath + File.separator + LOG_FILE_NAME);
		newConfig.setLimit(getInt("logging.files.limit", Defaults.LOGGING_FILES_LIMIT) * 1024);
		newConfig.setCount(getInt("logging.files.count", Defaults.LOGGING_FILES_COUNT));
		newConfig.setAppend(true);
		newConfig.setDatePattern(LOG_FILE_DATE_PATTERN);
		newConfig.setFormatter(new CustomFormatter("%1$td/%1$tm/%1$tY %1$tH:%1$tM:%1$tS.%tL %4$s %3$s - %5$s%6$s%n"));

		if (getBoolean("logging.files.autoclean.enabled", Defaults.LOGGING_FILES_AUTOCLEAN_ENABLED)) {
			final HousekeepingFilter hf = new HousekeepingFilter(logFileManager, getShort("logging.files.autoclean.keep", Defaults.LOGGING_FILES_AUTOCLEAN_KEEP), LOG_FILE_DATE_PATTERN);
			hf.addObserver(new Observer() {
				@Override
				public void update(final Observable o, final Object deletedFile) {
					LoggerFactory.getLogger(o.getClass()).log(Level.INFO, Messages.get("msg.logging.housekeeping.deleted"), deletedFile);
				}
			});
			newConfig.setFilter(hf);
		}

		if (fileHandler != null) {
			final TimeBasedRollingFileHandlerConfig oldConfig = TimeBasedRollingFileHandlerConfig.fromHandler(fileHandler);
			if (!oldConfig.getFileNamePattern().equals(newConfig.getFileNamePattern()) || oldConfig.getLimit() != newConfig.getLimit() || oldConfig.getCount() != newConfig.getCount() || !equals(oldConfig.getFilter(), newConfig.getFilter())) {
				logger.log(Level.FINE, "Logging configuration has changed; closing and removing old {0}...", fileHandler.getClass().getSimpleName());
				LoggingSupport.getRootLogger().removeHandler(fileHandler);
				fileHandler.close();
				fileHandler = null;
				logger.log(Level.FINE, "Old FileHandler closed and removed.");
			}
		}

		if (fileHandler == null) {
			logger.log(Level.FINE, "FileHandler not found; creating one...");
			try {
				new File(loggingPath).mkdirs();
				fileHandler = new TimeBasedRollingFileHandler(newConfig);
				LoggingSupport.getRootLogger().addHandler(fileHandler);
				logger.log(Level.FINE, "{0} created successfully.", fileHandler.getClass().getSimpleName());
			}
			catch (final IOException e) {
				logger.log(Level.SEVERE, e.toString(), e);
			}
		}
	}
}
 
開發者ID:Albertus82,項目名稱:RouterLogger,代碼行數:48,代碼來源:RouterLoggerConfig.java


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