本文整理汇总了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);
}
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
}