Reputation: 279
The SBT document says that "When a command is run, more detailed logging output is sent to a file than to the screen (by default). ..."
Where is the logging file?
If I use a logging function in my program, where can I find those logs after the program is finished?
Upvotes: 16
Views: 11809
Reputation: 25781
If you are simply trying to log to a file using an SLF4J compatible logger (as suggested by the link in your comment) I'd propose you use Logback for logging, as explained here.
It is fairly simple to configure (for simple use cases), including where log outputs are sent to. The linked to tutorial only configures a console appender, that is, the logged output will be sent to the console. You can configure a FileAppender
(i.e. sending log outputs to a file) like this (in your logback.xml
):
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>testFile.log</file>
<append>true</append>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
And then changing <appender-ref ref="STDOUT" />
from the tutorial to <appender-ref ref="FILE" />
. You should really take a look at the logback / SLF4J docs in order to figure out how to set up more complex logging configurations if you need it, but this should get you started.
After setting everything up (i.e. adding logback as a dependency in build.sbt
and creating your logback.xml
configuration in src/main/resources
), you can then invoke the logger like so:
import org.slf4j.LoggerFactory
import ch.qos.logback.core.util.StatusPrinter
import ch.qos.logback.classic.LoggerContext
object LogTester extends App{
def logger = LoggerFactory.getLogger("KDURLFilter")
StatusPrinter.print((LoggerFactory.getILoggerFactory).asInstanceOf[LoggerContext])
logger.info("vikas")
}
I've created an example SBT project in which you can see a running logback configuration.
Upvotes: 9