use of java.util.logging.FileHandler in project ignite by apache.
the class CommandHandler method setupJavaLogger.
/**
* @return prepared JULs logger.
*/
private Logger setupJavaLogger() {
Logger result = initLogger(CommandHandler.class.getName() + "Log");
// Adding logging to file.
try {
String absPathPattern = new File(JavaLoggerFileHandler.logDirectory(U.defaultWorkDirectory()), "control-utility-%g.log").getAbsolutePath();
FileHandler fileHandler = new FileHandler(absPathPattern, 5 * 1024 * 1024, 5);
fileHandler.setFormatter(new JavaLoggerFormatter());
result.addHandler(fileHandler);
} catch (Exception e) {
System.out.println("Failed to configure logging to file");
}
// Adding logging to console.
result.addHandler(setupStreamHandler());
return result;
}
use of java.util.logging.FileHandler in project ignite by apache.
the class JavaLoggerFileHandler method nodeId.
/**
* Sets Node id and instantiates {@link FileHandler} delegate.
*
* @param app Application name.
* @param workDir Path to the work directory.
* @param nodeId Node id.
*/
public void nodeId(@Nullable String app, UUID nodeId, String workDir) throws IgniteCheckedException, IOException {
if (delegate != null)
return;
String clsName = getClass().getName();
String ptrn = manager.getProperty(clsName + ".pattern");
if (ptrn == null)
ptrn = "%{app}-%{id8}.%g.log";
String fileName = ptrn.replace("%{app}", app != null ? app : "ignite").replace("%{id8}", U.id8(nodeId));
ptrn = new File(logDirectory(workDir), fileName).getAbsolutePath();
int limit = getIntProperty(clsName + ".limit", 0);
if (limit < 0)
limit = 0;
int cnt = getIntProperty(clsName + ".count", 1);
if (cnt <= 0)
cnt = 1;
boolean append = getBooleanProperty(clsName + ".append", false);
FileHandler delegate0;
synchronized (this) {
if (delegate != null)
return;
delegate = delegate0 = new FileHandler(ptrn, limit, cnt, append);
}
delegate0.setLevel(getLevel());
delegate0.setFormatter(getFormatter());
delegate0.setEncoding(getEncoding());
delegate0.setFilter(getFilter());
delegate0.setErrorManager(getErrorManager());
}
use of java.util.logging.FileHandler in project j2objc by google.
the class OldFileHandlerTest method testFileHandler_4params.
public void testFileHandler_4params() throws Exception {
int limit = 120;
int count = 1;
boolean append = false;
do {
append = !append;
handler = new FileHandler("%t/log/string", limit, count, 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", limit, count, 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("", limit, count, true);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
// expected
}
try {
new FileHandler("%t/log/string", -1, count, false);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
// expected
}
try {
new FileHandler("%t/log/string", limit, 0, true);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
// expected
}
}
use of java.util.logging.FileHandler in project j2objc by google.
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 Payara by payara.
the class LoggingExclusionTest method initializeLoggingTest.
private void initializeLoggingTest(String excludeFields) throws Exception {
Globals.setDefaultHabitat(serviceLocatorMock);
VersionInfo versionInfo = new VersionInfo() {
@Override
public String getAbbreviatedProductName() {
return ABBREVIATED_PRODUCT;
}
@Override
public String getVersionPrefix() {
return VERSION_PREFIX;
}
@Override
public String getMajorVersion() {
return VERSION_MAJOR;
}
@Override
public String getMinorVersion() {
return VERSION_MINOR;
}
@Override
public String getUpdateVersion() {
return VERSION_UPDATE;
}
};
Mockito.when(serviceLocatorMock.getService(VersionInfo.class)).thenReturn(versionInfo);
File basePath = new File(BASE_PATH);
basePath.mkdirs();
// Add a file handler with UniformLogFormatter
uniformFormatHandler = new FileHandler(ULF_LOG);
uniformFormatHandler.setLevel(Level.FINE);
uniformFormatHandler.setFormatter(new UniformLogFormatter(excludeFields));
// Add a file handler with ODLLogFormatter
odlFormatHandler = new FileHandler(ODL_LOG);
odlFormatHandler.setLevel(Level.FINE);
odlFormatHandler.setFormatter(new ODLLogFormatter(excludeFields));
// Add a file handler with JSONLogFormatter
jsonFormatHandler = new FileHandler(JSON_LOG);
jsonFormatHandler.setLevel(Level.FINE);
jsonFormatHandler.setFormatter(new JSONLogFormatter(excludeFields));
consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(new UniformLogFormatter(excludeFields));
LOGGER.addHandler(uniformFormatHandler);
LOGGER.addHandler(odlFormatHandler);
LOGGER.addHandler(jsonFormatHandler);
boolean enableConsoleHandler = Boolean.getBoolean(LoggingExclusionTest.class.getName() + ".enableConsoleHandler");
if (enableConsoleHandler) {
LOGGER.addHandler(consoleHandler);
}
LOGGER.setUseParentHandlers(false);
LOGGER.setLevel(Level.FINE);
}
Aggregations