/src/test/scala/com/codahale/logula/examples/ExampleLoggingRun.scala

http://github.com/codahale/logula · Scala · 58 lines · 46 code · 12 blank · 0 comment · 0 complexity · 7ab06fe337b3caceaa39becf2cdc76df MD5 · raw file

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