Fork me on GitHub
#clojure
<
2020-12-13
>
kwladyka08:12:46

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 🙂

Itay13:12:06

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.

p-himik13:12:25

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

valerauko16:12:03

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

Itay11:12:35

@U5RCSJ6BB 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.

Itay11:12:33

@U5RCSJ6BB Actually it doesn’t work at all.

rutledgepaulv12:12:44

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

Itay14:12:54

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.

andarp19:12:27

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

andarp19:12:06

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

borkdude19:12:50

I use AdoptOpenJDK ones and GraalVM

dharrigan19:12:34

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

andy.fingerhut19:12:12

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

dharrigan19:12:01

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.

andy.fingerhut20:12:16

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.

dharrigan20:12:55

Perhaps yes.

seancorfield20:12:03

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.

seancorfield20:12:01

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

seancorfield20:12:07

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.

didibus21:12:47

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

didibus21:12:31

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

seancorfield21:12:24

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.

didibus23:12:57

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,,,

didibus23:12:34

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

dharrigan19:12:29

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

☝️ 3
andy.fingerhut19:12:29

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.

kwladyka21:12:34

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

seancorfield22:12:49

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

kwladyka22:12:01

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

seancorfield22:12:18

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

kwladyka22:12:35

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

seancorfield22:12:35

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

kwladyka22:12:20

PS Did you see my “edit” in my message?

seancorfield22:12:17

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

hiredman22:12:27

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

seancorfield22:12:01

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

kwladyka22:12:18

I am saying it didn’t work, but now it works. I don’t know how and when I fixed it 🙂

seancorfield22:12:59

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

kwladyka22:12:13

yes, now it works without

kwladyka22:12:01

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.

kwladyka22:12:07

Which gave me false assumptions

seancorfield22:12:02

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

seancorfield22:12:53

monitorInterval = 30

seancorfield22:12:23

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.

seancorfield22:12:38

Nothing to do with clojure.tools.logging

kwladyka22:12:01

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?

kwladyka22:12:16

ok this is my luck of experience with loggers then 🙂

seancorfield22:12:38

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

kwladyka22:12:45

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&amp;cid=C03S1KBA2 load fresh file always

kwladyka22:12:13

My mistake, I though reload if by default

seancorfield22:12:36

Those pieces of code are not equivalent.

seancorfield22:12:06

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

kwladyka22:12:23

Thanks, now I know 🙂

seancorfield22:12:35

Java logging is a giant mess.

kwladyka22:12:10

BTW Do you have example which work in google cloud (exactly cloud run) as jsonPayload? I can’t make it work as expected 😕

seancorfield22:12:35

Nope, never used any of the Google Cloud stuff.

kwladyka22:12:00

ok, thank you for help

cjmurphy23:12:49

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.

phronmophobic23:12:45

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

cjmurphy00:12:36

Just need to know the points. Just data, no graphics. I'm going to use cljfx, but that's irrelevant to the function I'm looking for. Any kind of plot. I know there's different strategies and then surely known algorithms. https://en.wikipedia.org/wiki/Graph_drawing. So 'just an XY scatterplot'.

jjttjj00:12:47

There's not a ton of documentation but I've been using this to good effect. There are a bunch of examples in the "sketches" directory (results in "results" directory)

phronmophobic00:12:21

ohh, that kind of graph. For layouting out graphs (not charts), I've only seen wrappers around graphviz so far

jjttjj00:12:06

Oh, yeah sorry, I misunderstood as well

phronmophobic00:12:02

some libraries that use graphviz under the hood: • https://github.com/clojure/tools.deps.graphhttps://github.com/daveray/dorothy (it says it's still subject to change, but it hasn't changed in years)

phronmophobic00:12:20

I would also be interested in a library that does graph layout for you that runs on the jvm (no graphviz). would be great to hear if you find something

3
phronmophobic00:12:09

hmm, there is also https://github.com/totakke/jungerer which wraps http://jrtom.github.io/jung/ which has several graph layout implementations

cjmurphy00:12:20

Thanks @U7RJTCH6J. Yes I might take at look and see if easy to get something out with one of the JUNG implementations, for instance https://github.com/jrtom/jung/blob/master/jung-algorithms/src/main/java/edu/uci/ics/jung/layout/algorithms/SpringLayoutAlgorithm.java. Will definitely share if I can layout a graph from Clojure.

👍 3