clj-http uses the Apache HttpComponent client, which can log all outgoing calls using log4j2. See https://github.com/dakrone/clj-http#logging.
Using Logback, to enable logging of outgoing requests add this to logback.xml: <logger name="org.apache.http.wire" level="debug"/>
You can even change it runtime:
(.. (org.slf4j.LoggerFactory/getLogger "org.apache.http.wire")
(setLevel (ch.qos.logback.classic.Level/DEBUG)))
If I have both a my-ns.clj
and a my-ns.cljc
is it possible to refer the functions from the cljc namespace or am I forced to give it some other name?
The reason being that most of the code is CLJ code, so I would like to avoid indenting my entire CLJC file by having it in its own CLJ file.
With only the shared code in the CLJC file.
if you are using it from clojure, there is no way to get to the .cljc file as .clj is prioritized
ok, sucks
you have to give it another name. clojure is looking for foo.clj or foo.cljc when you require namespace declared in foo if you have both - I think only first will be loaded, but this is not stated anywhere in docs
ok - thanks for answering. I’ll move stuff around and try to come up with some new namespace name… sigh
you can rename the other one to _common.cljc
and then load that from your clojure file
I guess, but I just wanted the experience of CLJC. I guess I can just make it CLJC and live with crappy indentation everywhere.
Hello! Has anyone here packaged a Clojure project with both jlink
and jpackage
to produce a slimmed down deliverable for end users? I have an existing Java project that uses modules and is packaged with jpackage
and I would like to add Clojure to it. But all information I can find online are basically leiningen
plugins that run jlink
on Clojure only projects. Not sure how to translate that to my situation.
does jlink do tree shaking (automatic removal of unused classes) ? because that tends to not play nicely with clojure
TBH if you already know how to use jlink / jpackage you might just want to use those tools directly and define clojure.main (or if you absolutely need to, your own gen-class / aot ns) as the entry point. clojure is a java library and you can use java tooling.
"clojure only" just means "clojure is my only java lib outside the jre itself"
afaik you can use jlink and jpackage with Clojure - just AOT, then you've got bytecode, do whatever you're supposed to with jlink and jpackage
TIL:
(ns repro
(:import
(java.time format.DateTimeFormatter LocalDateTime)))
Does anyone actually else use import
like this?(it was a bug filed against clj-kondo)
You mean using (
instead of [
?
then I’m using import like that )
No, importing DateTimeFormatter
like this
I assume he means the nesting, not that
I don't see any support in the docstring that that is something you can do
oh, that would be good news, because I find it pretty confusing :)
the (clojure.)spec does tolerate it
I think this is about semantics, not sure the spec could cover this
I think the docstring suggests it isn't supported: package-symbol class-name-symbols*
so I could just close it like that
I think the fact that it does something useful is more likely by accident than intent
closed it: https://github.com/clj-kondo/clj-kondo/issues/1283
We were using that structure for imports in a couple of places in our (older) code at work but I think clj-kondo flagged the imported classes as unknown and when I looked at the :import
I was like “WAT?!” for a few seconds, surprised that it was actually legal in Clojure! I thought it was a horrible way to structure an :import
so I rewrote it to the “expected” structure — which satisfied clj-kondo (and my OCD).
I'm the one who raised that ticket on kondo, I've seen this structure in a few places, but I don't remember where I saw it first. I know it's been incredibly convenient for wrapper libraries, like the previously shown java.time, or in my experience the org.lwjgl namespaces.
As for the square brackets vs parens, I always use parens for imports because the first element of the sequence is in a "priviliged" position, in that it is a package, and the other elements are classes.
https://stuartsierra.com/2016/clojure-how-to-ns.html recommends [
..`]` for :require
and (
..`)` for :import
and I prefer that style but I know there are plenty of folks who prefer [
..`]` for both.
@suskeyhose Nesting is supported for namespaces (but this style is also discouraged by how to ns, but clj-kondo does recognize the style)
Hi All, I am using the JDBC library for Clojure with Postgres. I have some SQL that aggregates an array as a column value. On return I get the following error: java.lang.Exception: Not supported: class org.postgresql.jdbc.PgArray . What is a way around this?
pretty sure rich disagrees with that, uses []
for both
@looprecur Which JDBC library are you using? The next.jdbc
docs have a section on Working with Arrays https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.659/doc/getting-started/tips-tricks#working-with-arrays
Yeah, Rich is definitely on record as favoring []
for both. As is @alexmiller as I recall.
Feel free to follow-up in #sql where other PostgreSQL users may be able to help (it’s a lot lower traffic than this channel).
@seancorfield I'm using the older clojure.java.jdbc 0.7.12. I'll see if I can move to next.jdbc. Very grateful for the help.
c.j.j has a “similar” extension mechanism so you could probably “translate” the next.jdbc
approach to your own code but the protocol names are different and it’s much less well documented.
yep
Maybe I’ll get a T shirt made up that says (:import (i.am.with Stuart))
:rolling_on_the_floor_laughing:
Found this code snippet on SO that does the trick: https://stackoverflow.com/a/25786990
so I need to strip troublesome characters out of filenames and replace them with -. troublesome in this case forward/backward slashes, whitespace, underscore, punctuation etc.
trying to create one single match for clojure.string/replace
and this works; (clojure.string/replace "troublesome\\file .name" #"\s|_|\\|/" "-") -> "troublesome-file-.name"
however I can't figure out how to get rid of punctuation marks following the same pattern, adding |.
to the matcher just replaces everything suddenly
NEVERMIND, it works using a character class matcher: #"\s|\t|_|\\|/|[.]"
#"[\\/.|\s]"
is equivalent to that
but personally I'd take a whitelist approach like #[^a-zA-Z0-9_]