clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
kwladyka 2020-12-13T08:43:46.458200Z

Does anyone have an example of jsonPayload for cloud run (or something else) in google cloud https://cloud.google.com/run/docs/logging#writing_structured_logs to share with org.clojure/tools.logging? With log4j maybe? I am a little confuse how to do it in Clojure and in general šŸ™‚

Itay 2020-12-13T13:50:06.461100Z

I swear I tried really hard to find the answer on google but no luck: How do I suppress warnings in runtime? E.g.

WARNING: seqable? already refers to: #'clojure.core/seqable? in namespace: clostache.parser, being replaced by: #'clojure.core.incubator/seqable?
I understand that I canā€™t target these specifically, but Iā€™m really fine with disabling all possible kinds of warnings in order for these to disappear.

Itay 2020-12-15T11:43:35.036600Z

@rutledgepaulv wouldnā€™t this disable other errors/warnings as well? The context is we have many many Clojure components in production and we simply donā€™t have time to resolve each one of these warnings in each component (not in the near future, at least) - meanwhile, it creates a lot of noise in our logging/monitoring systems. I would like remove these warnings from production environments so we can focus on the real issues.

Itay 2020-12-15T11:59:33.040100Z

@rutledgepaulv Actually it doesnā€™t work at all.

rutledgepaulv 2020-12-15T12:56:44.040600Z

Yes, it removes all errors and warnings from the compiler. I don't recommend using it. I'm pretty sure it did work but last I tried it was several years ago. I'm not sure how you're bundling your app but if adding to your project.clj file it will have no bearing on jars you create and you'd have to find a way to run the same code before any of your problematic namespaces get loaded

Itay 2020-12-15T14:02:54.041500Z

It didnā€™t work with lein repl either. But I will try to simply plug it in the main ns. Very strange these things are not properly configurable.

p-himik 2020-12-13T13:51:25.461200Z

You can, in fact, exclude seqable? in particular: https://clojuredocs.org/clojure.core/refer-clojure

rutledgepaulv 2020-12-13T14:25:27.461400Z

I do not recommend doing this, but here: https://gist.github.com/RutledgePaulV/2cf1ccf6e561937206ac61f41041112d

valerauko 2020-12-13T16:22:03.461900Z

If you're the developer of the library then exclude with :refer-clojure. If you're not, then you can either monkey patch it locally or contribute to the library to resolve the warning

2020-12-13T19:28:27.463600Z

As someone without any substantial Java experience, what JDK is the standard one most people use nowadays? Still Oracle?

2020-12-13T19:29:06.464800Z

And does the local install of whatever JDK I choose actually affect anything in my writing of Clojure?

borkdude 2020-12-13T19:30:50.465100Z

I use AdoptOpenJDK ones and GraalVM

dharrigan 2020-12-13T19:54:34.466200Z

I use OpenJDK 11. Both it and AdoptOpenJDK are good choices

2020-12-13T19:57:12.468400Z

The choice of JDK will often not affect your writing of Clojure at all. The primary cases where you care about which JDK version you are using is if you are writing code, or using a Clojure or Java library, that uses Java API calls that were only added in a particular version of the JDK, and thus you will need that version or later, or if some library or code you are writing makes assumptions that were changed in later versions of the JDK (e.g. the module system in JDK 9 changed some things, and is probably the main reason why many people have stayed on JDK 8 for as long as they have).

dharrigan 2020-12-13T19:59:01.469900Z

It's interesting you mention the module system. As someone who has used Java from 1.1 onwards, I found absolutely zero issues when moving from Java 8 to Java 11 (and now Java 15). I wonder what problems people experienced.

2020-12-14T23:29:57.030800Z

Ya, I recon there might be a chicken and egg problem here. If they keep seeing so many people using 8 they might just keep extending support. But if people like me wait till support ends to upgrade,,,

2020-12-14T23:30:34.031Z

I'll get around to it at some point I'm sure, but its that thing of like, its working fine so why botter

dharrigan 2020-12-13T19:59:29.470900Z

I think it's a huge testiment to the engineering team behind the JVM that it's so well engineered and backwards compatible.

ā˜ļø 1
2020-12-13T19:59:29.471Z

Oracle changed their license model about 1-2 years ago, so many people avoid using it unless they already plan to pay Oracle for a commercial support license.

2020-12-13T20:04:16.471600Z

I am not a heavy JDK user myself except as a hobbyist, so can't give you good answers there. I would not be surprised if the main things convincing some people to continue using JDK 8 are that they rely upon some Java library that does not work well with JDK 9 or later, deep in its guts.

dharrigan 2020-12-13T20:04:55.471800Z

Perhaps yes.

seancorfield 2020-12-13T20:27:03.472200Z

Most of the issues, moving from 8 to 9 or above, were about reflection and access to parts of what became other modules. We got stuck on Java 8 for a while because some of the libraries we used did not run properly on 9+. We actually switched one library out for an alternative because it was so slow to properly support 9, and that allowed us to move to 11 which is what we're on in production right now.

seancorfield 2020-12-13T20:30:01.472400Z

It's been pretty smooth from 9 onward. I used 14 on my dev systems for a while, and I'm on 15 right now on my Mac (still on 14 on this Windows laptop, well, on Ubuntu). We've talked about upgrading our servers at work but there's nothing really compelling at the moment so we haven't decided which version we would upgrade to yet...

seancorfield 2020-12-13T20:31:07.472600Z

The main actual "breakage" when we upgraded from 8 to 11, was around JVM options which changed/went away. But that was easy to fix, albeit a bit annoying to roll out.

2020-12-13T21:01:47.472800Z

For us I think it's just there's no reason to move up from 8. And even if the friction won't be too hard, you'll still need to be upgrading dependencies and all, so it seems like a all pain no gain deal

2020-12-13T21:02:31.473Z

Until 8 is no longer supported, then we'll have a reason to upgrade

seancorfield 2020-12-13T21:35:24.473300Z

It looks like 8 will stay supported past the end of 11's support period, at this point. 14 is already past the end of its support. 17 is still nearly a year away from release.

kwladyka 2020-12-13T21:49:34.474900Z

(let [logger (LogManager/getLogger)]
    (.info logger "foo bar"))
works as expected with log4j2.xml configuration but if I use
(clojure.tools.logging/info "foo")
it looks like it ignores log4j2.xml why? The Factory is set:
(System/getProperty "clojure.tools.logging.factory")
=> "clojure.tools.logging.impl/log4j2-factory"
--- Ok I found an issue:
(binding [l/*logger-factory* (clojure.tools.logging.impl/log4j2-factory)]
    (l/info "foo"))
But have to find out why it is not set, while I have (System/getProperty "clojure.tools.logging.factory") set. --- edit: It finally works. I donā€™t know why it didnā€™t and why it works now, but probably solved.

seancorfield 2020-12-13T22:11:49.475500Z

@kwladyka How are you setting that property for your code?

kwladyka 2020-12-13T22:13:01.475800Z

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="ConsoleJSONAppender" target="SYSTEM_OUT">
            <JsonLayout complete="false" compact="false">
                <KeyValuePair key="myCustomField" value="myCustomValue"/>
            </JsonLayout>
        </Console>
    </Appenders>

    <Loggers>
        <Root level="all">
            <AppenderRef ref="ConsoleJSONAppender"/>
        </Root>
    </Loggers>
</Configuration>
I am trying to output JSON, but I am have to learn how to configure log4j2.xml - I have totally no experience about this.

seancorfield 2020-12-13T22:14:18.476Z

How are you setting that property? I'm not asking about XML.

kwladyka 2020-12-13T22:15:35.476200Z

:aliases {:dev {:extra-paths ["dev"]
                 :jvm-opts ["-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory"]
in deps.edn

seancorfield 2020-12-13T22:16:35.476400Z

"-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory" looks right. And you're starting things up with the :dev alias?

kwladyka 2020-12-13T22:17:05.476600Z

yes

kwladyka 2020-12-13T22:17:20.476800Z

PS Did you see my ā€œeditā€ in my message?

seancorfield 2020-12-13T22:18:17.477300Z

I can't understand what you're saying here.

2020-12-13T22:18:27.477500Z

Likely the issue is tools.logging has a specific order it chooses logging backends in, and any reasonable sized project ends up including all the logging backends

seancorfield 2020-12-13T22:19:01.477700Z

Yes, but the JVM property tells it to select the specified one. It's what we do at work.

kwladyka 2020-12-13T22:19:18.477900Z

I am saying it didnā€™t work, but now it works. I donā€™t know how and when I fixed it šŸ™‚

seancorfield 2020-12-13T22:19:59.478100Z

You shouldn't need that binding if you're setting the JVM property.

kwladyka 2020-12-13T22:20:13.478300Z

yes, now it works without

kwladyka 2020-12-13T22:34:01.478500Z

Ah I found the issueā€¦ for some reason when using clojure.tools.logging it doesnā€™t react for log4j2.xml file changes and reload configuration.

kwladyka 2020-12-13T22:35:07.478700Z

Which gave me false assumptions

seancorfield 2020-12-13T22:37:02.479Z

Hmm, we use a .properties file for it and it does reload changes (after a period of time) and I think it's something you have to configure in log4j2... let me see if I can remember what we did...

seancorfield 2020-12-13T22:37:53.479200Z

monitorInterval = 30

seancorfield 2020-12-13T22:38:23.479400Z

You should be able to set that in the XML file as well. Then it will monitor the XML file and pick up changes automatically.

seancorfield 2020-12-13T22:38:38.479600Z

Nothing to do with clojure.tools.logging

kwladyka 2020-12-13T22:39:01.479800Z

Is it not default?

(let [logger (LogManager/getLogger)]
    (.info logger "foo bar"))

  (binding [l/*logger-factory* (clojure.tools.logging.impl/log4j2-factory)]
    (l/info "foo"))
Does it mean code above always read file?

kwladyka 2020-12-13T22:39:16.480Z

ok this is my luck of experience with loggers then šŸ™‚

seancorfield 2020-12-13T22:39:38.480200Z

I don't understand what you're asking, but this has nothing to do with clojure.tools.logging. This is about configuring log4j2.

seancorfield 2020-12-13T22:40:34.480400Z

See https://logging.apache.org/log4j/2.x/manual/configuration.html

kwladyka 2020-12-13T22:40:45.480600Z

I mean the code above always work with fresh configuration file while (l/info ...) use old one. So it looks like https://clojurians.slack.com/archives/C03S1KBA2/p1607899141479800?thread_ts=1607897509.475500&cid=C03S1KBA2 load fresh file always

kwladyka 2020-12-13T22:41:13.480900Z

My mistake, I though reload if by default

seancorfield 2020-12-13T22:41:36.481100Z

Those pieces of code are not equivalent.

seancorfield 2020-12-13T22:42:06.481300Z

But reloading the XML file when you make changes is a configuration option in the XML file.

kwladyka 2020-12-13T22:42:23.481500Z

Thanks, now I know šŸ™‚

seancorfield 2020-12-13T22:42:35.481700Z

Java logging is a giant mess.

kwladyka 2020-12-13T22:43:10.481900Z

BTW Do you have example which work in google cloud (exactly cloud run) as jsonPayload? I canā€™t make it work as expected šŸ˜•

seancorfield 2020-12-13T22:43:35.482100Z

Nope, never used any of the Google Cloud stuff.

kwladyka 2020-12-13T22:44:00.482300Z

ok, thank you for help

cjmurphy 2020-12-13T23:33:49.484900Z

Does anyone know of a Clojure/Java library that might layout a graph in x,y coordinate space? I'm just looking to call a function that for each vertex will return an x,y place to put it.

phronmophobic 2020-12-13T23:49:45.485Z

do you need some amount of custom graphics, or just an XY scatterplot?