https://pantsbuild.org/ logo
#general
Title
# general
h

happy-kitchen-89482

06/19/2019, 3:18 PM
Can you post your BUILD file?
s

strong-caravan-64652

06/19/2019, 4:28 PM
Here is my server bundle build file:
Copy code
scala_library(
  name = 'scala_library',
  sources = globs('*.scala'),
  dependencies = [
    '3rdparty/jvm/com/twitter:finagle-http',
    '3rdparty/jvm/com/twitter:twitter-util',
    '3rdparty/jvm/io/circe',
    '3rdparty/jvm/io/finch',
    '3rdparty/jvm/org/sangria-graphql',
    '3rdparty/jvm/org/typelevel:cats',
    'src/jvm/com/thesigma/circe/lib',
    'src/jvm/com/thesigma/common/scala',
    'src/jvm/com/thesigma/config',
    'src/jvm/com/thesigma/effect/core',
    'src/jvm/com/thesigma/effect/enriched',
    'src/jvm/com/thesigma/encryptedtoken/service',
    'src/jvm/com/thesigma/redis/service',
    'src/jvm/com/thesigma/server/bag',
    'src/jvm/com/thesigma/server/base',
    'src/jvm/com/thesigma/server/finch',
    'src/jvm/com/thesigma/server/graphql/context',
    'src/jvm/com/thesigma/server/graphql/exception',
    'src/jvm/com/thesigma/server/graphql/executor',
    'src/jvm/com/thesigma/server/graphql/schema/main',
    'src/jvm/com/thesigma/tracing/context',
    'src/jvm/com/thesigma/user/login/service',
    'src/jvm/com/thesigma/validate',
    'src/resources/com/thesigma/html',
    'src/resources/com/thesigma/logback',
    'src/thrift/com/thesigma/encryptedtoken',
    'src/thrift/com/thesigma/ids',
  ],
)

jvm_binary(
  name = 'bin',
  dependencies = [
    ':scala_library',
    'src/resources/com/thesigma/logback',
  ],
  main = 'com.thesigma.server.graphql.bin.GraphQlServer',
  basename = 'graphqlserver',
  deploy_jar_rules=jar_rules(rules=[
    Duplicate('^BUILD', Duplicate.SKIP),
    Duplicate('^META-INF/ASL2.0', Duplicate.SKIP),
    Duplicate('^META-INF/INDEX.LIST', Duplicate.SKIP),
    Duplicate('^META-INF/io.netty.versions.properties', Duplicate.SKIP),
    Duplicate('^rootdoc.txt', Duplicate.SKIP),
  ]),
)
And the build file for my resource:
Copy code
# Copyright 2019 Merit International, Inc. All Rights Reserved.

resources(
  name = 'logback',
  sources = rglobs('*.xml'),
)
@happy-kitchen-89482 ^
h

happy-kitchen-89482

06/19/2019, 4:31 PM
And this second file is
src/resources/com/thesigma/logback/BUILD
?
s

strong-caravan-64652

06/19/2019, 4:31 PM
Yep
h

happy-kitchen-89482

06/19/2019, 4:33 PM
And your application is, I assume, looking for resource
logback.xml
in the
com.thesigma.logback
package?
s

strong-caravan-64652

06/19/2019, 4:34 PM
So, logback just looks for a file
logback.xml
anywhere on the classpath. Not sure if the package comes into play
Copy code
Let us begin by discussing the initialization steps that logback follows to try to configure itself:

Logback tries to find a file called logback-test.xml in the classpath.

If no such file is found, logback tries to find a file called logback.groovy in the classpath.

If no such file is found, it checks for the file logback.xml in the classpath..

If no such file is found, service-provider loading facility (introduced in JDK 1.6) is used to resolve the implementation of com.qos.logback.classic.spi.Configurator interface by looking up the file META-INF\services\ch.qos.logback.classic.spi.Configurator in the class path. Its contents should specify the fully qualified class name of the desired Configurator implementation.

If none of the above succeeds, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.
https://logback.qos.ch/manual/configuration.html
h

happy-kitchen-89482

06/19/2019, 4:38 PM
Ah, so that might be the problem.
Can you
jar -t
the jarfile and see where that logback.xml file is?
jar -t <jarfile> | grep logback.xml
s

strong-caravan-64652

06/19/2019, 4:42 PM
Taking forever on my machine...but someone else on my team just poked me with something similar, said that it's in
com/thesigma/logback/logback.xml
h

happy-kitchen-89482

06/19/2019, 4:43 PM
OK, so there's the issue
Logback code expects
logback.xml
in the root of the package hierarchy
s

strong-caravan-64652

06/19/2019, 4:43 PM
...is it really that simple? 😂
h

happy-kitchen-89482

06/19/2019, 4:44 PM
Pants infers "source roots" from your directory structure (e.g., if it sees "src/foo" it assumes that's the package root of a language called "foo"). This works for resources as well.
You can override the source roots in
pants.ini
, but I don't think that's the right call here
s

strong-caravan-64652

06/19/2019, 4:44 PM
So since we've got
src/jvm
, I should just put it in there?
h

happy-kitchen-89482

06/19/2019, 4:45 PM
I think you probably want to put
logback.xml
directly under
src/resources
(or
src/jvm
), so that the structure in your source tree accurately reflects what will happen in the JAR file.
Yep, you can create a
resources()
target in
src/jvm/BUILD
or
src/resources/BUILD
You could also make
src/resources/com/thesigma/logback
a source root, but that seems perverse.
s

strong-caravan-64652

06/19/2019, 4:47 PM
Let me see if it works in just
src/resources
, I think the team will like that better than dropping it in
src/jvm
Yes it works there! Perfect!
Thanks again @happy-kitchen-89482
h

happy-kitchen-89482

06/19/2019, 4:53 PM
great!
2 Views