use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testPublish_EmptyMsg.
/*
* Test publish(), a log record with empty msg, having output stream
*/
public void testPublish_EmptyMsg() {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
LogRecord r = new LogRecord(Level.INFO, "");
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head", aos.toString());
}
use of java.util.logging.StreamHandler in project jreversepro by akkumar.
the class CustomLoggerFactory method createLogger.
public static Logger createLogger() {
final Logger logger = Logger.getLogger("JReversePro");
final SimpleFormatter formatter = new SimpleFormatter();
final StreamHandler handler = new StreamHandler(System.out, formatter);
logger.addHandler(handler);
logger.setLevel(Level.FINER);
return logger;
}
use of java.util.logging.StreamHandler in project neo4j by neo4j.
the class SuppressOutput method java_util_logging.
public static Suppressible java_util_logging(final ByteArrayOutputStream redirectTo, Level level) {
final Handler replacement = redirectTo == null ? null : new StreamHandler(redirectTo, new SimpleFormatter());
if (replacement != null && level != null) {
replacement.setLevel(level);
}
return new Suppressible() {
@Override
public Voice suppress() {
final Logger logger = LogManager.getLogManager().getLogger("");
final Level level = logger.getLevel();
final Handler[] handlers = logger.getHandlers();
for (Handler handler : handlers) {
logger.removeHandler(handler);
}
if (replacement != null) {
logger.addHandler(replacement);
logger.setLevel(Level.ALL);
}
return new Voice(this, redirectTo) {
@Override
void restore(boolean failure) throws IOException {
for (Handler handler : handlers) {
logger.addHandler(handler);
}
logger.setLevel(level);
if (replacement != null) {
logger.removeHandler(replacement);
}
}
};
}
};
}
use of java.util.logging.StreamHandler in project android_frameworks_base by AOSPA.
the class CookiesTest method testCookiesAreNotLogged.
/**
* Test that we don't log potentially sensitive cookie values.
* http://b/3095990
*/
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
// enqueue an HTTP response with a cookie that will be rejected
server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
server.play();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Logger logger = Logger.getLogger("org.apache.http");
StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
logger.addHandler(handler);
try {
HttpClient client = new DefaultHttpClient();
client.execute(new HttpGet(server.getUrl("/").toURI()));
handler.close();
String log = out.toString("UTF-8");
assertTrue(log, log.contains("password"));
assertTrue(log, log.contains("fake.domain"));
assertFalse(log, log.contains("secret"));
} finally {
logger.removeHandler(handler);
}
}
use of java.util.logging.StreamHandler in project robovm by robovm.
the class OldFormatterTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
h = new StreamHandler();
}
Aggregations