Esempio n. 1
0
  @Test
  public void testNamedLogger() {
    jul.clear();
    JavaUtilLog log = new JavaUtilLog("test");
    log.info("Info test");

    jul.assertContainsLine("INFO|test|Info test");

    JavaUtilLog loglong = new JavaUtilLog("test.a.long.name");
    loglong.info("Long test");

    jul.assertContainsLine("INFO|test.a.long.name|Long test");
  }
Esempio n. 2
0
  @Test
  public void testDebugOutput() {
    jul.clear();

    // Common Throwable (for test)
    Throwable th = new Throwable("Message");

    // Capture raw string form
    StringWriter tout = new StringWriter();
    th.printStackTrace(new PrintWriter(tout));
    String ths = tout.toString();

    // Tests
    JavaUtilLog log = new JavaUtilLog("test.de.bug");
    setJulLevel("test.de.bug", Level.FINE);

    log.debug("Simple debug");
    log.debug("Debug with {} parameter", 1);
    log.debug("Debug with {} {} parameters", 2, "spiffy");
    log.debug("Debug with throwable", th);
    log.debug(th);

    // jul.dump();

    jul.assertContainsLine("FINE|test.de.bug|Simple debug");
    jul.assertContainsLine("FINE|test.de.bug|Debug with 1 parameter");
    jul.assertContainsLine("FINE|test.de.bug|Debug with 2 spiffy parameters");
    jul.assertContainsLine("FINE|test.de.bug|Debug with throwable");
    jul.assertContainsLine(ths);
  }
Esempio n. 3
0
  @Test
  public void testWarnOutput() {
    jul.clear();

    // Common Throwable (for test)
    Throwable th = new Throwable("Message");

    // Capture raw string form
    StringWriter tout = new StringWriter();
    th.printStackTrace(new PrintWriter(tout));
    String ths = tout.toString();

    // Tests
    JavaUtilLog log = new JavaUtilLog("test.wa.rn");
    setJulLevel("test.wa.rn", Level.WARNING);

    log.warn("Simple warn");
    log.warn("Warn with {} parameter", 1);
    log.warn("Warn with {} {} parameters", 2, "spiffy");
    log.warn("Warn with throwable", th);
    log.warn(th);

    // jul.dump();

    jul.assertContainsLine("WARNING|test.wa.rn|Simple warn");
    jul.assertContainsLine("WARNING|test.wa.rn|Warn with 1 parameter");
    jul.assertContainsLine("WARNING|test.wa.rn|Warn with 2 spiffy parameters");
    jul.assertContainsLine("WARNING|test.wa.rn|Warn with throwable");
    jul.assertContainsLine(ths);
  }
Esempio n. 4
0
  @Test
  public void testInfoOutput() {
    jul.clear();

    // Common Throwable (for test)
    Throwable th = new Throwable("Message");

    // Capture raw string form
    StringWriter tout = new StringWriter();
    th.printStackTrace(new PrintWriter(tout));
    String ths = tout.toString();

    // Tests
    JavaUtilLog log = new JavaUtilLog("test.in.fo");
    setJulLevel("test.in.fo", Level.INFO);

    log.info("Simple info");
    log.info("Info with {} parameter", 1);
    log.info("Info with {} {} parameters", 2, "spiffy");
    log.info("Info with throwable", th);
    log.info(th);

    // jul.dump();

    jul.assertContainsLine("INFO|test.in.fo|Simple info");
    jul.assertContainsLine("INFO|test.in.fo|Info with 1 parameter");
    jul.assertContainsLine("INFO|test.in.fo|Info with 2 spiffy parameters");
    jul.assertContainsLine("INFO|test.in.fo|Info with throwable");
    jul.assertContainsLine(ths);
  }
Esempio n. 5
0
  @Test
  public void testFormattingWithNulls() {
    jul.clear();

    JavaUtilLog log = new JavaUtilLog("test.nu.ll");
    setJulLevel("test.nu.ll", Level.INFO);

    log.info("Testing info(msg,null,null) - {} {}", "arg0", "arg1");
    log.info("Testing info(msg,null,null) - {}/{}", null, null);
    log.info("Testing info(msg,null,null) > {}", null, null);
    log.info("Testing info(msg,null,null)", null, null);
    log.info(null, "Testing", "info(null,arg0,arg1)");
    log.info(null, null, null);

    // jul.dump();

    jul.assertContainsLine("INFO|test.nu.ll|Testing info(msg,null,null) - null/null");
    jul.assertContainsLine("INFO|test.nu.ll|Testing info(msg,null,null) > null null");
    jul.assertContainsLine("INFO|test.nu.ll|Testing info(msg,null,null) null null");
    jul.assertContainsLine("INFO|test.nu.ll|null Testing info(null,arg0,arg1)");
    jul.assertContainsLine("INFO|test.nu.ll|null null null");
  }
Esempio n. 6
0
  @Test
  public void testIsDebugEnabled() {
    JavaUtilLog log = new JavaUtilLog("test.legacy");

    setJulLevel("test.legacy", Level.ALL);
    Assert.assertThat("log.level(all).isDebugEnabled", log.isDebugEnabled(), is(true));

    setJulLevel("test.legacy", Level.FINEST);
    Assert.assertThat("log.level(finest).isDebugEnabled", log.isDebugEnabled(), is(true));

    setJulLevel("test.legacy", Level.FINER);
    Assert.assertThat("log.level(finer).isDebugEnabled", log.isDebugEnabled(), is(true));

    setJulLevel("test.legacy", Level.FINE);
    Assert.assertThat("log.level(fine).isDebugEnabled", log.isDebugEnabled(), is(true));

    setJulLevel("test.legacy", Level.INFO);
    Assert.assertThat("log.level(info).isDebugEnabled", log.isDebugEnabled(), is(false));

    setJulLevel("test.legacy", Level.WARNING);
    Assert.assertThat("log.level(warn).isDebugEnabled", log.isDebugEnabled(), is(false));

    log.setDebugEnabled(true);
    Assert.assertThat("log.isDebugEnabled", log.isDebugEnabled(), is(true));

    log.setDebugEnabled(false);
    Assert.assertThat("log.isDebugEnabled", log.isDebugEnabled(), is(false));
  }