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 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);
}
}
use of java.util.logging.FileHandler in project robovm by robovm.
the class OldFileHandlerTest method testInvalidParams.
// This test fails on RI. Doesn't parse special pattern \"%t/%h."
public void testInvalidParams() throws IOException {
// bad directory, IOException, append
try {
new FileHandler("%t/baddir/multi%g", true);
fail("should throw IO exception");
} catch (IOException e) {
}
File file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0");
assertFalse(file.exists());
try {
new FileHandler("%t/baddir/multi%g", false);
fail("should throw IO exception");
} catch (IOException e) {
}
file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0");
assertFalse(file.exists());
try {
new FileHandler("%t/baddir/multi%g", 12, 4);
fail("should throw IO exception");
} catch (IOException e) {
}
file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0");
assertFalse(file.exists());
try {
new FileHandler("%t/java%u", -1, -1);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
use of java.util.logging.FileHandler in project robovm by robovm.
the class OldFileHandlerTest method testFileHandler_1params.
public void testFileHandler_1params() throws Exception {
handler = new FileHandler("%t/log/string");
assertEquals("character encoding is non equal to actual value", "iso-8859-1", handler.getEncoding());
assertNotNull("Filter is null", handler.getFilter());
assertNotNull("Formatter is null", handler.getFormatter());
assertEquals("is non equal to actual value", Level.FINE, handler.getLevel());
assertNotNull("ErrorManager is null", handler.getErrorManager());
handler.publish(r);
handler.close();
// append mode is true
for (int i = 0; i < 3; i++) {
handler = new FileHandler("%t/log/string");
handler.publish(r);
handler.close();
}
assertFileContent(TEMPPATH + SEP + "log", "/string", new LogRecord[] { r, null, r, null, r, null, r }, new MockFormatter());
// test if unique ids not specified, it will append at the end
// no generation number is used
FileHandler h = new FileHandler("%t/log/string");
FileHandler h2 = new FileHandler("%t/log/string");
FileHandler h3 = new FileHandler("%t/log/string");
FileHandler h4 = new FileHandler("%t/log/string");
h.publish(r);
h2.publish(r);
h3.publish(r);
h4.publish(r);
h.close();
h2.close();
h3.close();
h4.close();
assertFileContent(TEMPPATH + SEP + "log", "string", h.getFormatter());
assertFileContent(TEMPPATH + SEP + "log", "string.1", h.getFormatter());
assertFileContent(TEMPPATH + SEP + "log", "string.2", h.getFormatter());
assertFileContent(TEMPPATH + SEP + "log", "string.3", h.getFormatter());
// default is append mode
FileHandler h6 = new FileHandler("%t/log/string%u.log");
h6.publish(r);
h6.close();
FileHandler h7 = new FileHandler("%t/log/string%u.log");
h7.publish(r);
h7.close();
try {
assertFileContent(TEMPPATH + SEP + "log", "string0.log", h.getFormatter());
fail("should assertion failed");
} catch (Error e) {
}
File file = new File(TEMPPATH + SEP + "log");
assertTrue("length list of file is incorrect", file.list().length <= 2);
// test unique ids
FileHandler h8 = new FileHandler("%t/log/%ustring%u.log");
h8.publish(r);
FileHandler h9 = new FileHandler("%t/log/%ustring%u.log");
h9.publish(r);
h9.close();
h8.close();
assertFileContent(TEMPPATH + SEP + "log", "0string0.log", h.getFormatter());
assertFileContent(TEMPPATH + SEP + "log", "1string1.log", h.getFormatter());
file = new File(TEMPPATH + SEP + "log");
assertTrue("length list of file is incorrect", file.list().length <= 2);
try {
new FileHandler("");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
//expected
}
}
use of java.util.logging.FileHandler in project robovm by robovm.
the class OldFileHandlerTest method testFileHandler_2params.
public void testFileHandler_2params() throws Exception {
boolean append = false;
do {
append = !append;
handler = new FileHandler("%t/log/string", append);
assertEquals("character encoding is non equal to actual value", "iso-8859-1", handler.getEncoding());
assertNotNull("Filter is null", handler.getFilter());
assertNotNull("Formatter is null", handler.getFormatter());
assertEquals("is non equal to actual value", Level.FINE, handler.getLevel());
assertNotNull("ErrorManager is null", handler.getErrorManager());
handler.publish(r);
handler.close();
// append mode is true
for (int i = 0; i < 3; i++) {
handler = new FileHandler("%t/log/string", append);
handler.publish(r);
handler.close();
}
if (append) {
assertFileContent(TEMPPATH + SEP + "log", "/string", new LogRecord[] { r, null, r, null, r, null, r }, new MockFormatter());
} else {
assertFileContent(TEMPPATH + SEP + "log", "/string", new LogRecord[] { r }, new MockFormatter());
}
} while (append);
try {
new FileHandler("", true);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
//expected
}
}
Aggregations