I am having an issue with the logging of a transitive dependency in my project, https://github.com/sbmlteam/jsbml It has the habit of writing to a log file and in doing so captures the entire log output of my application. I have not been able to override this behaviour so far. Unfortunately, the project does not compile anymore because one of its dependencies vanished, so I cannot really fix it there. Java logging is still somewhat confusing to me, is there somebody here who could help me ask the right questions to deal with this issue? What I want to achieve is to just make the library stop capturing log output to file. From what I can see β’ org.apache.logging.log4j:log4j-1.2-api:2.17.1 β’ org.apache.logging.log4j:log4j-api:2.17.1 β’ org.apache.logging.log4j:log4j-core:2.17.1 β’ org.apache.logging.log4j:log4j-slf4j-impl:2.17.1 are the libraries in question here. In my project right now I have
[org.slf4j/slf4j-api "1.7.32"]
[org.slf4j/jul-to-slf4j "1.7.32"]
[org.slf4j/jcl-over-slf4j "1.7.32"]
[org.slf4j/log4j-over-slf4j "1.7.32"]
[org.slf4j/osgi-over-slf4j "1.7.32"]
[ch.qos.logback/logback-classic "1.2.3"]
in an attempt to whack all problems like these, which obviously kind of failedYou're probably going to need to add :exclusions to your jsbml dependency to exclude at least some of those log4j 2.17.1 dependencies. https://lambdaisland.com/blog/2020-06-12-logging-in-clojure-making-sense-of-the-mess talks about excluding transitive logging dependencies in order to force logging overall to use your preferred libraries.
Yeah I remembered you told me earlier ... I don't really know if this is gonna interfere with that, but I realized that (I assume) since I am using an uberjar of a downstream library the dependencies on those logging libraries dont show up in lein deps tree
How exactly are you specifying the dependency on jsbml? I used this command to look at the list of dependencies:
clojure -Sdeps '{:deps {org.sbml.jsbml/jsbml {:mvn/version "1.6.1"}}}' -Spath | tr ':' '\n' | sort
so I'm expecting something like [org.sbml.jsbml/jsbml "1.6.1"] in your project.clj file?I didn't. My project included a jar that included jsbml, which was originally developed as an application, not a library. I am writing a webserver for it and naively just included the application jar (of the project downstream of jsbml) which was an uberjar. But that seems to be resolved, because I can just rebuild the first downstream project of jsbml and now require it myself, so I see the deps and all ... never mind me, its a mess here and I don't know exactly what I am doing
Thanks for your patiently telling me to read the damn blog post though. π
What is the "downstream project" that you had to build yourself? Is that not available as a dependency?
Nah ... nah this is academia ... and not the good kind
I actually have another question though - the server I am writing will basically take a file, run a huge script on it and return a file - for each of those runs, I would like to put a run ID into all log messages that arise from it. I feel like this should be fairly easy to do but I am kind of clueless
I mean, a way short of just modifying the Java code
log4j supports "MDC" which lets you add "context" to logging and have it printed out in the messages, and it can act in a nested manner. I'm not sure if slf4j supports that.
But you're definitely getting off into the weeds if you start using that (we do it at work, so code can attach any additional context it needs for code it is executing, in case that produces log messages).
logback supports it, which I use now Thanks, gonna read up on it.
Works like a charm!
what dependency vanished, out of curiosity?
org.mangosdk.spi
hmm
well the code is still out there
and looking at what this library does - you could rip it out pretty easy
Well to be more specific the problem I encountered was that I was not able to build jsbml using the pom. They also have an ant script which apparently works. However, since I was already shaving a massive yak and figured out how to whack their logging config unconscious downstream I didn't bother looking into this any further.
is there anything like instaparse for java?
Thereβs clj-antlr btw
antlr, i guess? If you made an instaparse in Java you'd need to have some dynamic representation of the AST. Certainly possible, but I don't think anyone's gone down that road