use of java.util.logging.FileHandler in project CoreNLP by stanfordnlp.
the class SieveCoreferenceSystem method initializeAndRunCoref.
/** Returns the name of the log file that this method writes. */
public static String initializeAndRunCoref(Properties props) throws Exception {
String timeStamp = Calendar.getInstance().getTime().toString().replaceAll("\\s", "-").replaceAll(":", "-");
//
// initialize logger
//
String logFileName = props.getProperty(Constants.LOG_PROP, "log.txt");
if (logFileName.endsWith(".txt")) {
logFileName = logFileName.substring(0, logFileName.length() - 4) + "_" + timeStamp + ".txt";
} else {
logFileName = logFileName + "_" + timeStamp + ".txt";
}
try {
FileHandler fh = new FileHandler(logFileName, false);
logger.addHandler(fh);
logger.setLevel(Level.FINE);
fh.setFormatter(new NewlineLogFormatter());
} catch (SecurityException | IOException e) {
throw new RuntimeException("Cannot initialize logger!", e);
}
logger.fine(timeStamp);
logger.fine(props.toString());
Constants.printConstants(logger);
// initialize coref system
SieveCoreferenceSystem corefSystem = new SieveCoreferenceSystem(props);
// MentionExtractor extracts MUC, ACE, or CoNLL documents
MentionExtractor mentionExtractor;
if (props.containsKey(Constants.MUC_PROP)) {
mentionExtractor = new MUCMentionExtractor(corefSystem.dictionaries, props, corefSystem.semantics, corefSystem.singletonPredictor);
} else if (props.containsKey(Constants.ACE2004_PROP) || props.containsKey(Constants.ACE2005_PROP)) {
mentionExtractor = new ACEMentionExtractor(corefSystem.dictionaries, props, corefSystem.semantics, corefSystem.singletonPredictor);
} else if (props.containsKey(Constants.CONLL2011_PROP)) {
mentionExtractor = new CoNLLMentionExtractor(corefSystem.dictionaries, props, corefSystem.semantics, corefSystem.singletonPredictor);
} else {
throw new RuntimeException("No input file specified!");
}
if (!Constants.USE_GOLD_MENTIONS) {
// Set mention finder
String mentionFinderClass = props.getProperty(Constants.MENTION_FINDER_PROP);
if (mentionFinderClass != null) {
String mentionFinderPropFilename = props.getProperty(Constants.MENTION_FINDER_PROPFILE_PROP);
CorefMentionFinder mentionFinder;
if (mentionFinderPropFilename != null) {
Properties mentionFinderProps = new Properties();
FileInputStream fis = new FileInputStream(mentionFinderPropFilename);
mentionFinderProps.load(fis);
fis.close();
mentionFinder = (CorefMentionFinder) Class.forName(mentionFinderClass).getConstructor(Properties.class).newInstance(mentionFinderProps);
} else {
mentionFinder = (CorefMentionFinder) Class.forName(mentionFinderClass).newInstance();
}
mentionExtractor.setMentionFinder(mentionFinder);
}
if (mentionExtractor.mentionFinder == null) {
logger.warning("No mention finder specified, but not using gold mentions");
}
}
if (corefSystem.optimizeSieves && corefSystem.sieves.length > 1) {
corefSystem.optimizeSieveOrdering(mentionExtractor, props, timeStamp);
}
try {
runAndScoreCoref(corefSystem, mentionExtractor, props, timeStamp);
} catch (Exception ex) {
logger.log(Level.SEVERE, "ERROR in running coreference", ex);
}
logger.info("done");
String endTimeStamp = Calendar.getInstance().getTime().toString().replaceAll("\\s", "-");
logger.fine(endTimeStamp);
return logFileName;
}
use of java.util.logging.FileHandler in project heron by twitter.
the class LoggingHelper method getFileHandler.
/**
* Initialize a <tt>FileHandler</tt> to write to a set of files
* with optional append. When (approximately) the given limit has
* been written to one file, another file will be opened. The
* output will cycle through a set of count files.
* The pattern of file name should be: ${processId}.log.index
* <p>
* The <tt>FileHandler</tt> is configured based on <tt>LogManager</tt>
* properties (or their default values) except that the given pattern
* argument is used as the filename pattern, the file limit is
* set to the limit argument, and the file count is set to the
* given count argument, and the append mode is set to the given
* <tt>append</tt> argument.
* <p>
* The count must be at least 1.
*
* @param limit the maximum number of bytes to write to any one file
* @param count the number of files to use
* @param append specifies append mode
* @throws IOException if there are IO problems opening the files.
* @throws SecurityException if a security manager exists and if
* the caller does not have <tt>LoggingPermission("control")</tt>.
* @throws IllegalArgumentException if {@code limit < 0}, or {@code count < 1}.
* @throws IllegalArgumentException if pattern is an empty string
*/
public static FileHandler getFileHandler(String processId, String loggingDir, boolean append, int limit, int count) throws IOException, SecurityException {
String pattern = loggingDir + "/" + processId + ".log.%g";
FileHandler fileHandler = new FileHandler(pattern, limit, count, append);
fileHandler.setFormatter(new SimpleFormatter());
fileHandler.setEncoding("UTF-8");
return fileHandler;
}
use of java.util.logging.FileHandler in project OpenAM by OpenRock.
the class ToolLogWriter method init.
/**
* Initializes the logger with environment parameters.
*/
public static void init() throws IOException {
String logName = getLogName();
logger = Logger.getLogger(ToolLogWriter.class.getName());
fh = new FileHandler(logName, true);
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
//log only above the log level specified
logger.setLevel(getLogLevel());
logger.setUseParentHandlers(false);
String status = "";
status = SystemProperties.get(ToolConstants.PROPERTY_LOG_ENABLED, "off");
enabled = status.equalsIgnoreCase("on") ? true : false;
}
use of java.util.logging.FileHandler in project 360-Engine-for-Android by 360.
the class LogUtils method enableLogcat.
/**
* Enable logging.
*/
public static void enableLogcat() {
mEnabled = true;
/** Enable the SD Card logger **/
sLogger = Logger.getLogger(APP_NAME_PREFIX);
try {
FileHandler fileHandler = new FileHandler(APP_FILE_NAME, LOG_FILE_LIMIT, LOG_FILE_COUNT);
fileHandler.setFormatter(new Formatter() {
@Override
public String format(final LogRecord logRecord) {
StringBuilder sb = new StringBuilder();
sb.append(DATE_FORMAT.format(new Date(logRecord.getMillis())));
sb.append(" ");
sb.append(logRecord.getMessage());
sb.append("\n");
return sb.toString();
}
});
sLogger.addHandler(fileHandler);
} catch (IOException e) {
logE("LogUtils.logToFile() IOException, data will not be logged " + "to file", e);
sLogger = null;
}
if (Settings.ENABLED_PROFILE_ENGINES) {
/** Enable the SD Card profiler **/
sProfileLogger = Logger.getLogger("profiler");
try {
FileHandler fileHandler = new FileHandler("/sdcard/engineprofiler.log", LOG_FILE_LIMIT, LOG_FILE_COUNT);
fileHandler.setFormatter(new Formatter() {
@Override
public String format(final LogRecord logRecord) {
StringBuilder sb = new StringBuilder();
sb.append(DATE_FORMAT.format(new Date(logRecord.getMillis())));
sb.append("|");
sb.append(logRecord.getMessage());
sb.append("\n");
return sb.toString();
}
});
sProfileLogger.addHandler(fileHandler);
} catch (IOException e) {
logE("LogUtils.logToFile() IOException, data will not be logged " + "to file", e);
sProfileLogger = null;
}
}
}
use of java.util.logging.FileHandler in project Asqatasun by Asqatasun.
the class AsqatasunCrawlJob method closeCrawlerLogFiles.
/**
* Heritrix lets its log files opened at the end of the crawl.
* We have to close them "manually".
*/
private void closeCrawlerLogFiles() {
List<FileHandler> loggerHandlerList = new ArrayList<>();
for (Handler handler : crawlJob.getJobLogger().getHandlers()) {
if (handler instanceof FileHandler) {
((FileHandler) handler).close();
loggerHandlerList.add((FileHandler) handler);
}
}
for (FileHandler fileHandler : loggerHandlerList) {
crawlJob.getJobLogger().removeHandler(fileHandler);
}
}
Aggregations