java

Schmoho 2024-07-25T19:24:53.336639Z

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 failed

seancorfield 2024-07-25T19:48:08.725279Z

You'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.

Schmoho 2024-07-25T19:49:49.053289Z

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

seancorfield 2024-07-25T19:51:49.026449Z

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?

Schmoho 2024-07-25T19:54:54.651299Z

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

Schmoho 2024-07-25T19:55:53.277999Z

Thanks for your patiently telling me to read the damn blog post though. πŸ™‚

seancorfield 2024-07-25T20:12:46.939789Z

What is the "downstream project" that you had to build yourself? Is that not available as a dependency?

Schmoho 2024-07-25T20:13:31.685529Z

Nah ... nah this is academia ... and not the good kind

πŸ““ 1
🀣 1
🏫 1
Schmoho 2024-07-25T20:16:48.004209Z

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

Schmoho 2024-07-25T20:19:04.283459Z

I mean, a way short of just modifying the Java code

seancorfield 2024-07-25T20:20:31.705119Z

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.

seancorfield 2024-07-25T20:22:23.456149Z

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).

Schmoho 2024-07-25T20:26:34.884109Z

logback supports it, which I use now Thanks, gonna read up on it.

Schmoho 2024-07-25T20:53:59.735529Z

Works like a charm!

πŸ‘πŸ» 1
emccue 2024-07-27T11:48:14.433879Z

what dependency vanished, out of curiosity?

Schmoho 2024-07-27T11:50:55.306079Z

org.mangosdk.spi

emccue 2024-07-27T11:52:23.062889Z

hmm

emccue 2024-07-27T11:52:27.388999Z

well the code is still out there

emccue 2024-07-27T11:52:58.516009Z

https://github.com/rspilker/spi/tree/master

emccue 2024-07-27T11:53:22.264899Z

and looking at what this library does - you could rip it out pretty easy

Schmoho 2024-07-27T11:55:37.690229Z

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.

Drew Verlee 2024-07-25T19:50:16.738589Z

is there anything like instaparse for java?

jumar 2024-07-30T04:50:31.516659Z

There’s clj-antlr btw

emccue 2024-07-27T11:50:57.225089Z

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

πŸ‘€ 1