/src/test/scala/com/codahale/logula/tests/FormatterSpec.scala

http://github.com/codahale/logula · Scala · 35 lines · 27 code · 8 blank · 0 comment · 0 complexity · 12aa2cc65415ca0571d25acf956fc44d MD5 · raw file

  1. package com.codahale.logula.tests
  2. import com.codahale.simplespec.Spec
  3. import com.codahale.logula.Formatter
  4. import org.apache.log4j.{Level, Logger}
  5. import org.apache.log4j.spi.LoggingEvent
  6. import org.junit.Test
  7. class FormatterSpec extends Spec {
  8. class `Logula's formatter` {
  9. val formatter = new Formatter
  10. @Test def `handles exceptions itself` = {
  11. formatter.ignoresThrowable.must(be(false))
  12. }
  13. @Test def `formats entries as a single line` = {
  14. val event = new LoggingEvent("", Logger.getLogger("com.example.Yay"), 1270516531000L, Level.INFO, "That's a spicy pizza", null)
  15. formatter.format(event).must(be(
  16. "INFO [2010-04-06 01:15:31,000] com.example.Yay: That's a spicy pizza\n"
  17. ))
  18. }
  19. @Test def `formats exceptions as multiple lines` = {
  20. val throwable = new IllegalArgumentException("augh")
  21. val event = new LoggingEvent("", Logger.getLogger("com.example.Yay"), 1270516531000L, Level.INFO, "That's a spicy pizza", throwable)
  22. val entry = formatter.format(event)
  23. entry.startsWith("INFO [2010-04-06 01:15:31,000] com.example.Yay: That's a spicy pizza\n").must(be(true))
  24. entry.contains("! java.lang.IllegalArgumentException: augh").must(be(true))
  25. }
  26. }
  27. }