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