开发者

Debugging and Logging in Lift Using SBT

开发者 https://www.devze.com 2023-03-15 15:39 出处:网络
Im trying to get basic logging and debugging working in Lift using the SBT. Im using Eclipse as an editor but do开发者_Go百科ing all the compilation with SBT. Can anyone suggest how to print debug sta

Im trying to get basic logging and debugging working in Lift using the SBT. Im using Eclipse as an editor but do开发者_Go百科ing all the compilation with SBT. Can anyone suggest how to print debug statements/logging to the SBT console?


If you want to have logging with Logback, you need to create a basic xml file named src/main/resources/props/default.logback.xml (the filename can be different to reflect development and production environments, but we’ll keep it simple).

In this file, a basic configuration which will log to the console looks like:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="debug">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

(More examples can be found in the Logback manual.)

Next, you’ll need to add the dependency

"ch.qos.logback" % "logback-classic" % "0.9.26"

to your sbt configuration.

Finally, if you want to log from a class, mix in the trait Logger and you get all the debug, info, warn,… methods in scope.

class SomeClass extends SomeOtherClass with Logger {
    debug("Class initialised.")
}

Or, alternatively mix in Loggable which does not pollute your namespace and only provides a logger proxy method.

class SomeClass extends SomeOtherClass with Loggable {
    logger.debug("Class initialised.")
}

For more info, have a look at the Lift wiki.


In sbt there is console-quick command that loads web site environment in your command line. It's not a real time debugging tool that has break point, step by step execution but you can call methods on command line see the actual results which is sometimes really helpful.

0

精彩评论

暂无评论...
验证码 换一张
取 消