Search in sources :

Example 6 with Logger

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]);
}
Also used : Random(java.util.Random) RealParameter(beast.core.parameter.RealParameter) Logger(beast.core.Logger)

Aggregations

Logger (beast.core.Logger)6 RealParameter (beast.core.parameter.RealParameter)3 BEASTObject (beast.core.BEASTObject)2 BEASTInterface (beast.core.BEASTInterface)1 Alignment (beast.evolution.alignment.Alignment)1 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)1 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)1 SiteModel (beast.evolution.sitemodel.SiteModel)1 Base (beast.evolution.sitemodel.SiteModelInterface.Base)1 SubstitutionModel (beast.evolution.substitutionmodel.SubstitutionModel)1 XMLParser (beast.util.XMLParser)1 IOException (java.io.IOException)1 Random (java.util.Random)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 SAXException (org.xml.sax.SAXException)1