use of beast.core.Logger in project beast2 by CompEvol.
the class LoggerTest method testFileLog.
@Test
public void testFileLog() throws Exception {
logger = new Logger();
logger.initByName("fileName", "beast.log", "log", new RealParameter(new Double[] { 0.3, 0.7 }));
File f_log = new File(logger.fileNameInput.get());
if (f_log.exists()) {
boolean log_deleted = f_log.delete();
System.out.println("Delete log : " + f_log.getAbsolutePath() + " for testFileLog.");
}
logger.init();
assertTrue("beast.log created successfully", f_log.exists());
// rI >= 0
int rI = new Random().nextInt(10000000);
logger.log(-1);
logger.log(rI);
logger.close();
// TODO cannot get "closing" status from PrintStream
// assertNull("m_out is beast.log after close", logger.getM_out());
BufferedReader in = new BufferedReader(new FileReader(f_log));
// column names
String line = in.readLine();
// 1st sample
String sample1 = in.readLine();
String[] sp = sample1.split("\t", -1);
assertFalse("check beast.log -1 not logged", sp[0].equals("-1"));
assertEquals("check beast.log 1st sample", Integer.toString(rI), sp[0]);
}
Aggregations