/src/test/scala/com/codahale/logula/examples/ExampleLoggingRun.scala
Scala | 58 lines | 46 code | 12 blank | 0 comment | 0 complexity | 7ab06fe337b3caceaa39becf2cdc76df MD5 | raw file
1package com.codahale.logula.examples 2 3import com.codahale.logula.Logging 4import org.apache.log4j.Level 5 6class ThingDoer extends Logging { 7 def run() { 8 log.trace("Contemplating doing a thing.") 9 log.debug("About to do a thing.") 10 log.info("Doing a thing") 11 log.warn("This may get ugly.") 12 13 try { 14 error("oh noes!") 15 } catch { 16 case e: Exception => log.error(e, "The thing has gone horribly wrong.") 17 } 18 19 log.fatal("Just kidding!") 20 } 21} 22 23class SilencedRunner extends Logging { 24 def run() { 25 log.warn("BLAH BLAH BLAH BLAH BLAH BLAH BLAH") 26 log.warn("BLAH BLAH BLAH BLAH BLAH BLAH BLAH") 27 log.warn("BLAH BLAH BLAH BLAH BLAH BLAH BLAH") 28 log.warn("BLAH BLAH BLAH BLAH BLAH BLAH BLAH") 29 log.warn("BLAH BLAH BLAH BLAH BLAH BLAH BLAH") 30 log.warn("BLAH BLAH BLAH BLAH BLAH BLAH BLAH") 31 } 32} 33 34object ExampleLoggingRun extends Logging { 35 def main(args: Array[String]) { 36 Logging.configure { log => 37 log.registerWithJMX = true 38 39 log.level = Level.TRACE 40 41 log.loggers("com.codahale.logula.examples.SilencedRunner") = Level.OFF 42 43 log.console.enabled = true 44 log.console.threshold = Level.ALL 45 46 log.file.enabled = true 47 log.file.filename = "./logs/example-logging-run.log" 48 log.file.threshold = Level.ALL 49 50 log.syslog.enabled = true 51 log.syslog.host = "localhost" 52 log.syslog.facility = "LOCAL7" 53 } 54 55 new ThingDoer().run() 56 new SilencedRunner().run() 57 } 58}