本文整理汇总了Java中org.apache.log4j.WriterAppender.setImmediateFlush方法的典型用法代码示例。如果您正苦于以下问题:Java WriterAppender.setImmediateFlush方法的具体用法?Java WriterAppender.setImmediateFlush怎么用?Java WriterAppender.setImmediateFlush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.WriterAppender
的用法示例。
在下文中一共展示了WriterAppender.setImmediateFlush方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupLoggers
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
* Setup the main loggers for Novoa benchmarking routine.
*/
public void setupLoggers() {
LoggerHelper.setupRootLogger(LoggerHelper.LEVEL_WARN, LoggerHelper.LEVEL_WARN, true);
// Configuring loggers
Logger.getRootLogger().setLevel(LoggerHelper.LEVEL_WARN);
// MSA
MSALogging.getBaseLogger().setLevel(LoggerHelper.LEVEL_WARN);
// CW
CWLogging.getBaseLogger().setLevel(LoggerHelper.LEVEL_WARN);
// VLS
VLSLogging.getBaseLogger().setLevel(LoggerHelper.LEVEL_WARN);
// Heuristics
HeuristicsLogging.getBaseLogger().setLevel(LoggerHelper.LEVEL_WARN);
WriterAppender logAppender = new WriterAppender(DEFAULT_LOGGER_LAYOUT, err);
logAppender.setThreshold(LoggerHelper.LEVEL_WARN);
logAppender.setImmediateFlush(true);
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(logAppender);
}
示例2: setUp
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
public void setUp() throws Exception {
super.setUp();
writer = new StringWriter();
WriterAppender appender = new WriterAppender(new SimpleLayout(), writer);
appender.setImmediateFlush(true);
Logger logger = Logger.getRootLogger();
logger.addAppender(appender);
logger.setLevel(Level.INFO);
}
示例3: testValidIpv6AddressInQuorum
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
@Test
public void testValidIpv6AddressInQuorum() throws Exception {
assumeIPv6Available();
ClientBase.setupTestEnv();
// setup the logger to capture all logs
Layout layout =
Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
qlogger.addAppender(appender);
try {
final int CLIENT_PORT_QP1 = PortAssignment.unique();
final int CLIENT_PORT_QP2 = PortAssignment.unique();
String quorumCfgSection =
"server.1=127.0.0.1:" + PortAssignment.unique()
+ ":" + PortAssignment.unique()
+ "\nserver.2=[0:0:0:0:0:0:0:1]:" + PortAssignment.unique()
+ ":" + PortAssignment.unique();
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
q1.start();
q2.start();
Assert.assertTrue("waiting for server 1 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server 2 being up",
ClientBase.waitForServerUp("[0:0:0:0:0:0:0:1]:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT));
q1.shutdown();
q2.shutdown();
Assert.assertTrue("waiting for server 1 down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server 2 down",
ClientBase.waitForServerDown("[0:0:0:0:0:0:0:1]:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT));
} finally {
qlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
String line;
boolean found = false;
Pattern p =
Pattern.compile(".*Resolved hostname: 0:0:0:0:0:0:0:1.*");
while ((line = r.readLine()) != null) {
found = p.matcher(line).matches();
if (found) {
break;
}
}
Assert.assertTrue("IPv6 address resolved", found);
}
示例4: testInvalidIpv6AddressInQuorum
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
@Test
public void testInvalidIpv6AddressInQuorum() throws Exception {
assumeIPv6Available();
ClientBase.setupTestEnv();
// setup the logger to capture all logs
Layout layout =
Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
qlogger.addAppender(appender);
try {
final int CLIENT_PORT_QP1 = PortAssignment.unique();
String quorumCfgSection =
"server.1=127.0.0.1:" + PortAssignment.unique()
+ ":" + PortAssignment.unique()
+ "\nserver.2=[0:0:0:0:0:0:0:1:" + PortAssignment.unique()
+ ":" + PortAssignment.unique();
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
q1.start();
boolean isup =
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
30000);
Assert.assertFalse("Server never came up", isup);
q1.shutdown();
Assert.assertTrue("waiting for server 1 down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT));
} finally {
qlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
String line;
boolean found = false;
Pattern p =
Pattern.compile(".*QuorumPeerConfig\\$ConfigException.*");
while ((line = r.readLine()) != null) {
found = p.matcher(line).matches();
if (found) {
break;
}
}
Assert.assertTrue("complains about configuration", found);
}
示例5: testQuorumDefaults
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
* Verify handling of quorum defaults
* * default electionAlg is fast leader election
*/
@Test
public void testQuorumDefaults() throws Exception {
ClientBase.setupTestEnv();
// setup the logger to capture all logs
Layout layout =
Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger zlogger = Logger.getLogger("org.apache.zookeeper");
zlogger.addAppender(appender);
try {
final int CLIENT_PORT_QP1 = PortAssignment.unique();
final int CLIENT_PORT_QP2 = PortAssignment.unique();
String quorumCfgSection =
"server.1=127.0.0.1:" + PortAssignment.unique()
+ ":" + PortAssignment.unique()
+ "\nserver.2=127.0.0.1:" + PortAssignment.unique()
+ ":" + PortAssignment.unique();
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
q1.start();
q2.start();
Assert.assertTrue("waiting for server 1 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server 2 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
CONNECTION_TIMEOUT));
q1.shutdown();
q2.shutdown();
Assert.assertTrue("waiting for server 1 down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server 2 down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2,
ClientBase.CONNECTION_TIMEOUT));
} finally {
zlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
String line;
boolean found = false;
Pattern p =
Pattern.compile(".*FastLeaderElection.*");
while ((line = r.readLine()) != null) {
found = p.matcher(line).matches();
if (found) {
break;
}
}
Assert.assertTrue("fastleaderelection used", found);
}
示例6: testSeekForRwServer
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
* Ensures that client seeks for r/w servers while it's connected to r/o
* server.
*/
@SuppressWarnings("deprecation")
@Test(timeout = 90000)
public void testSeekForRwServer() throws Exception {
// setup the logger to capture all logs
Layout layout = Logger.getRootLogger().getAppender("CONSOLE")
.getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger zlogger = Logger.getLogger("org.apache.zookeeper");
zlogger.addAppender(appender);
try {
qu.shutdown(2);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(),
CONNECTION_TIMEOUT, watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// if we don't suspend a peer it will rejoin a quorum
qu.getPeer(1).peer.suspend();
// start two servers to form a quorum; client should detect this and
// connect to one of them
watcher.reset();
qu.start(2);
qu.start(3);
ClientBase.waitForServerUp(qu.getConnString(), 2000);
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
// resume poor fellow
qu.getPeer(1).peer.resume();
} finally {
zlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os
.toString()));
String line;
Pattern p = Pattern.compile(".*Majority server found.*");
boolean found = false;
while ((line = r.readLine()) != null) {
if (p.matcher(line).matches()) {
found = true;
break;
}
}
Assert.assertTrue(
"Majority server wasn't found while connected to r/o server",
found);
}
示例7: testQuorumDefaults
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
* Verify handling of quorum defaults
* * default electionAlg is fast leader election
*/
@Test
public void testQuorumDefaults() throws Exception {
ClientBase.setupTestEnv();
// setup the logger to capture all logs
Layout layout =
Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger zlogger = Logger.getLogger("org.apache.zookeeper");
zlogger.addAppender(appender);
try {
final int CLIENT_PORT_QP1 = PortAssignment.unique();
final int CLIENT_PORT_QP2 = PortAssignment.unique();
String quorumCfgSection =
"server.1=127.0.0.1:" + PortAssignment.unique()
+ ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1
+ "\nserver.2=127.0.0.1:" + PortAssignment.unique()
+ ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2;
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
q1.start();
q2.start();
Assert.assertTrue("waiting for server 1 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server 2 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
CONNECTION_TIMEOUT));
q1.shutdown();
q2.shutdown();
Assert.assertTrue("waiting for server 1 down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server 2 down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2,
ClientBase.CONNECTION_TIMEOUT));
} finally {
zlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
String line;
boolean found = false;
Pattern p =
Pattern.compile(".*FastLeaderElection.*");
while ((line = r.readLine()) != null) {
found = p.matcher(line).matches();
if (found) {
break;
}
}
Assert.assertTrue("fastleaderelection used", found);
}
示例8: testSeekForRwServer
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
* Ensures that client seeks for r/w servers while it's connected to r/o
* server.
*/
@SuppressWarnings("deprecation")
@Test(timeout = 90000)
public void testSeekForRwServer() throws Exception {
// setup the logger to capture all logs
Layout layout = Logger.getRootLogger().getAppender("CONSOLE")
.getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger zlogger = Logger.getLogger("org.apache.zookeeper");
zlogger.addAppender(appender);
try {
qu.shutdown(2);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(),
CONNECTION_TIMEOUT, watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// if we don't suspend a peer it will rejoin a quorum
qu.getPeer(1).peer.suspend();
// start two servers to form a quorum; client should detect this and
// connect to one of them
watcher.reset();
qu.start(2);
qu.start(3);
ClientBase.waitForServerUp(qu.getConnString(), 2000);
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
// resume poor fellow
qu.getPeer(1).peer.resume();
} finally {
zlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os
.toString()));
String line;
Pattern p = Pattern.compile(".*Majority server found.*");
boolean found = false;
while ((line = r.readLine()) != null) {
if (p.matcher(line).matches()) {
found = true;
break;
}
}
Assert.assertTrue(
"Majority server wasn't found while connected to r/o server",
found);
}
示例9: testSeekForRwServer
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
* Ensures that client seeks for r/w servers while it's connected to r/o
* server.
*/
@SuppressWarnings("deprecation")
@Test
public void testSeekForRwServer() throws Exception {
// setup the logger to capture all logs
Layout layout = Logger.getRootLogger().getAppender("CONSOLE")
.getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger zlogger = Logger.getLogger("org.apache.zookeeper");
zlogger.addAppender(appender);
try {
qu.shutdown(2);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(),
CONNECTION_TIMEOUT, watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// if we don't suspend a peer it will rejoin a quorum
qu.getPeer(1).peer.suspend();
// start two servers to form a quorum; client should detect this and
// connect to one of them
watcher.reset();
qu.start(2);
qu.start(3);
ClientBase.waitForServerUp(qu.getConnString(), 2000);
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
// resume poor fellow
qu.getPeer(1).peer.resume();
} finally {
zlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os
.toString()));
String line;
Pattern p = Pattern.compile(".*Majority server found.*");
boolean found = false;
while ((line = r.readLine()) != null) {
if (p.matcher(line).matches()) {
found = true;
break;
}
}
Assert.assertTrue(
"Majority server wasn't found while connected to r/o server",
found);
}
示例10: CLogOut
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
private CLogOut() {
final ByteArrayOutputStream stdStream = new ByteArrayOutputStream(){
@Override
public synchronized void flush() throws IOException {
String theString=toString();
/* OK:
Establishing connection.
Twitter Stream consumer-1[Establishing connection]
Connection established.
Receiving status stream.
Twitter Stream consumer-1[Receiving stream]
*Received:{...}
Twitter Stream consumer-1[Disposing thread]
*/
/* WRONG:
Establishing connection.
Twitter Stream consumer-1[Establishing connection]
Exceeded connection limit for user
420
Waiting for 10000 milliseconds
Twitter Stream consumer-1[Disposing thread]
*/
Platform.runLater(()->{
if(theString.startsWith("Establishing connection")){
message.set("Establishing connection...\n Please, wait a few seconds");
} else if(theString.startsWith("Receiving status stream")){
message.set("Receiving tweets!! \n Press stop button to stop the search");
} else if(theString.startsWith("Exceeded connection limit")){
message.set("Exceeded connection limit...");
} else if(theString.startsWith("Waiting for ")){
message.set(theString +" or press stop button to stop the search");
} else if(theString.contains("Disposing thread")){
message.set("The search has finished");
}
});
System.out.print("***** "+theString);
reset();
}
};
Logger root = Logger.getRootLogger();
WriterAppender writerAppender = new WriterAppender(new PatternLayout("%m%n"), stdStream);
root.addAppender(writerAppender);
writerAppender.setImmediateFlush(true);
}
示例11: testQuorumDefaults
import org.apache.log4j.WriterAppender; //导入方法依赖的package包/类
/**
* Verify handling of quorum defaults
* * default electionAlg is fast leader election
*/
@Test
public void testQuorumDefaults() throws Exception {
LOG.info("STARTING " + getName());
ClientBase.setupTestEnv();
// setup the logger to capture all logs
Layout layout =
Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger zlogger = Logger.getLogger("org.apache.zookeeper");
zlogger.addAppender(appender);
try {
final int CLIENT_PORT_QP1 = PortAssignment.unique();
final int CLIENT_PORT_QP2 = PortAssignment.unique();
String quorumCfgSection =
"server.1=127.0.0.1:" + PortAssignment.unique()
+ ":" + PortAssignment.unique()
+ "\nserver.2=127.0.0.1:" + PortAssignment.unique()
+ ":" + PortAssignment.unique();
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
q1.start();
q2.start();
assertTrue("waiting for server 1 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
CONNECTION_TIMEOUT));
assertTrue("waiting for server 2 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
CONNECTION_TIMEOUT));
q1.shutdown();
q2.shutdown();
assertTrue("waiting for server 1 down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT));
assertTrue("waiting for server 2 down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2,
ClientBase.CONNECTION_TIMEOUT));
} finally {
zlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
String line;
boolean found = false;
Pattern p =
Pattern.compile(".*FastLeaderElection.*");
while ((line = r.readLine()) != null) {
found = p.matcher(line).matches();
if (found) {
break;
}
}
assertTrue("fastleaderelection used", found);
}