use of java.util.logging.Formatter in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method createCommandHandler.
/**
*/
private CommandHandler createCommandHandler(ListeningTestLogger testLog) {
Logger log = CommandHandler.initLogger(null);
log.addHandler(new StreamHandler(System.out, new Formatter() {
/**
* {@inheritDoc}
*/
@Override
public String format(LogRecord record) {
String msg = record.getMessage();
testLog.info(msg);
return msg + "\n";
}
}));
return new CommandHandler(log);
}
use of java.util.logging.Formatter in project buck by facebook.
the class JavaUtilsLoggingBuildListener method ensureLogFileIsWritten.
public static void ensureLogFileIsWritten(ProjectFilesystem filesystem) {
if (!filesystem.exists(filesystem.getBuckPaths().getScratchDir())) {
try {
filesystem.mkdirs(filesystem.getBuckPaths().getScratchDir());
} catch (IOException e) {
throw new HumanReadableException(e, "Unable to create output directory: %s: %s: %s", filesystem.getBuckPaths().getScratchDir(), e.getClass(), e.getMessage());
}
}
try {
FileHandler handler = new FileHandler(filesystem.resolve(filesystem.getBuckPaths().getScratchDir()).resolve("build.log").toString(), /* append */
false);
Formatter formatter = new BuildEventFormatter();
handler.setFormatter(formatter);
LOG.setUseParentHandlers(false);
LOG.addHandler(handler);
LOG.setLevel(LEVEL);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of java.util.logging.Formatter in project cogtool by cogtool.
the class CogTool method enableLogging.
public static void enableLogging(boolean value) {
if (value) {
logger.setLevel(Level.ALL);
for (Handler h : logger.getHandlers()) {
if (h instanceof FileHandler) {
return;
}
}
FileHandler fh = null;
try {
fh = new FileHandler((CogToolPref.LOG_DIRECTORY.getString() + LOG_FILE_PATTERN), LOG_FILE_MAX_SIZE, LOG_FILES_MAX_COUNT, true);
} catch (IOException ex) {
logger.warning("Couldn't create log file: " + ex);
return;
}
fh.setFormatter(new Formatter() {
@Override
public String format(LogRecord r) {
long ms = r.getMillis();
return String.format("%tF %tT.%tL\t%s\n", ms, ms, ms, r.getMessage());
}
});
logger.addHandler(fh);
} else {
logger.setLevel(DEFAULT_LOG_LEVEL);
for (Handler h : logger.getHandlers()) {
if (!(h instanceof ConsoleHandler)) {
logger.removeHandler(h);
}
}
}
}
use of java.util.logging.Formatter in project j2objc by google.
the class MemoryHandlerTest method testClose.
/*
public void testSecurity() {
SecurityManager currentManager = System.getSecurityManager();
System.setSecurityManager(securityManager);
try {
try {
handler.close();
fail("should throw security exception");
} catch (SecurityException e) {
}
try {
handler.setPushLevel(Level.CONFIG);
fail("should throw security exception");
} catch (SecurityException e) {
}
handler.flush();
handler.push();
handler.getPushLevel();
handler.isLoggable(new LogRecord(Level.ALL, "message"));
handler.publish(new LogRecord(Level.ALL, "message"));
} finally {
System.setSecurityManager(currentManager);
}
}
*/
public void testClose() {
Filter filter = handler.getFilter();
Formatter formatter = handler.getFormatter();
writer.getBuffer().setLength(0);
handler.close();
assertEquals(writer.toString(), "close");
assertEquals(handler.getFilter(), filter);
assertEquals(handler.getFormatter(), formatter);
assertNull(handler.getEncoding());
assertNotNull(handler.getErrorManager());
assertEquals(handler.getLevel(), Level.OFF);
assertEquals(handler.getPushLevel(), Level.WARNING);
assertFalse(handler.isLoggable(new LogRecord(Level.SEVERE, "test")));
}
use of java.util.logging.Formatter in project j2objc by google.
the class HandlerTest method testGetSetFormatter_Normal.
/*
* Test setFilter with insufficient privilege.
*
public void testSetFilter_InsufficientPrivilege() throws Exception {
MockHandler h = new MockHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
// set null
try {
h.setFilter(null);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
// set a normal value
System.setSecurityManager(new MockSecurityManager());
try {
h.setFilter(new MockFilter());
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
*/
/*
* Test getFormatter & setFormatter methods with non-null value.
*/
public void testGetSetFormatter_Normal() throws Exception {
MockHandler h = new MockHandler();
Formatter f = new SimpleFormatter();
h.setFormatter(f);
assertSame(f, h.getFormatter());
}
Aggregations