I am using mill as my build tool. And I put the logback.xml - the config file for logback - under resources folder. However, it is not picked up by logback config. When I was using sbt, it took it from src/main/resources.
How do I get mill to put logback.xml in the right folder for logback to pick it up?
If you run the command
mill show <yourModulename>.resources
is logback.xml in the folder it displays?
Unless you override def resources
or mix-in one of the traits MavenModule
or SbtModule
, the default resource folder in Mill is resources
, not src/main/resources
. Your logback.xml
is most likely not in the right location.
You can check with
> mill show __.resources
If that doesn’t bring clarity, please post your build.sc
, so we don’t need to guess in the dark.
Yes, I am using resources
folder. I tried putting logback.xml in resources
and resources/podcaster
(podcaster is my module name), but I am not getting logback to print logs.
$ ./mill show podcaster.resources
[1/1] show
1 targets failed
show Cannot resolve podcaster.resources. Try `mill resolve _` or `mill resolve __.resources` to see what's available.
$ ./mill show _.resources
[1/1] show > [1/1] test.resources
[
"ref:v0:c984eca8:/Users/swadnerkar/Workspace/Scala/podcaster/test/resources"
]
And here is my build.sc
import mill._, scalalib._
object podcaster extends RootModule with ScalaModule {
def scalaVersion = "3.5.0"
// compile flags
def scalacOptions = Seq(
"-feature",
"-deprecation"
)
def ivyDeps = Agg(
ivy"com.lihaoyi::mainargs:0.7.2",
ivy"com.softwaremill.sttp.client4::core:4.0.0-M17",
ivy"org.scala-lang.modules::scala-xml:2.2.0",
ivy"org.tomlj:tomlj:1.1.1",
ivy"com.typesafe.scala-logging::scala-logging:3.9.5",
ivy"ch.qos.logback:logback-classic:1.3.5"
)
object test extends ScalaTests {
def ivyDeps = Agg(ivy"com.lihaoyi::utest:0.8.4")
def testFramework = "utest.runner.Framework"
}
}
You need to put it into
/Users/swadnerkar/Workspace/Scala/podcaster/test/resources
to have it when running the tests, or
/Users/swadnerkar/Workspace/Scala/podcaster/resources
to always have it on the classpath.
Your first mill show podcaster.resources
gave you an error because you defined podcaster
as RootModule
. It is just mill show resources
.
Also, check that your logback.xml
is really configured to print to the console.
I started seeing the logs now!
I was experimenting and I had moved the logback.xml under resources/podcaster
swadnerkar[~/Workspace/Scala/podcaster] (main*) $ ./mill show resources
[1/1] show > [1/1] resources
[
"ref:v0:715b8e91:/Users/swadnerkar/Workspace/Scala/podcaster/resources"
]
swadnerkar[~/Workspace/Scala/podcaster] (main*) $ tree resources/
resources/
└── logback.xml
1 directory, 1 file
swadnerkar[~/Workspace/Scala/podcaster] (main*) $ cat resources/logback.xml
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %logger{36} %-5level -%kvp- %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Good to hear.
That’s still confusing. There is no podcaster
dir under resources
in your listings above.
I meant I had put the logback.xml in resources/podcaster
, and when I moved it to the right location resources
, I started seeing the logs.