Suppress clojure logging in Eclipse? - java

I'm working with a 3rd party library implemented in Clojure which logs messages using clojure.tools.logging.
I want to suppress these messages in Eclipse and have tried the following suggestion to no avail.
Any (hacky) solutions greatly appreciated.

It sounds like your clojure.tools.logging is using a different underlying logging implementation than the rest of your application?
For example if your application is using java.util.logging, but you have a stray log4j library in your classpath, then clojure.tools.logging would detect log4j and would therefore not react to the logging config changes you were making.
The logic for detecting the underlying logging implementation is here:
https://github.com/clojure/tools.logging/blob/master/src/main/clojure/clojure/tools/logging/impl.clj
Specifically:
(defn find-factory
"Returns the first non-nil value from slf4j-factory, cl-factory,
log4j-factory, and jul-factory."
[]
(or (slf4j-factory)
(cl-factory)
(log4j-factory)
(jul-factory)
(throw ; this should never happen in 1.5+
(RuntimeException.
"Valid logging implementation could not be found."))))
It would be helpful to run mvn dependency:tree or lein deps :tree to see what logging dependencies are on your classpath.

Related

How to turn off all logging (even for dependencies) in a standalone command-line app (jar-with-dependencies)

I have an Java app that depends on a whole bunch of libraries. I use the assembly maven plugin to package the whole thing into a single JAR.
This library is mostly used a regular JAR dependency, so the client will be controlling logging. However, when it's packaged as a standalone executable JAR, I don't want to show all these logs that you would usually see in the server log.
I obviously don't control what type of logging libraries dependencies use. In my main, I use the JDK java.util.logging.
How do I programmatically turn off all logging (or leave it only at SEVERE level)?
I have tried to do what is suggested here (with the variation that I set the level to SEVERE) at the very start in my main, but all the logs are still showing up.
How do I get the logs to stop showing up on the command-line when I execute the JAR?
How do I get the logs to stop showing up on the command-line when I execute the JAR?
If you want to be heavy handed you can stop all console output by simply closing the out and error streams:
System.out.close();
System.err.close();
Keep in mind there is no way to re-open those streams.
How do I programmatically turn off all logging (or leave it only at SEVERE level)?
For JUL you can follow the instructions to create a logging.properties file.
I obviously don't control what type of logging libraries dependencies use...
You'll have to have to include configuration files for those frameworks to turn them off.
How do I programmatically turn off all logging (or leave it only at SEVERE level)?
Child loggers will inherit from the root logger. You can set the root logger to severe and set it's handlers to severe:
private static final Logger[] PINS = new Logger[]{Logger.getLogger("")};
static {
for (Logger l : PINS) {
l.setLevel(Level.SEVERE);
for (Handler h : l.getHanders()) {
h.setLevel(Level.SEVERE);
}
}
}

Components index generated by spring-context-indexer seems to do nothing

The spring.components file in not generated.
The problem is described in-depth in https://github.com/spring-projects/spring-framework/issues/22338.
As turns out, in Gradle 4.6+ (that includes Gradle 5.x - I have verified in Gradle 5.1.1 and 5.2), the correct declaration is annotationProcessor 'org.springframework:spring-context-indexer:5.1.4.RELEASE'.
More questions for the good folks from Spring Boot - should the spring.components file be created in ./BOOT-INF/classes/META-INF/spring.components? That's where is shows up for me, but I would expect it in ./META-INF/spring.components.
Also, how can I see that the file is indeed produced & used? Any flags to toggle? Any specific packages to turn verbose logging for? Any Actuator endpoint to look at?

print a console Value from a jar file to GUI

I am running a dynamic spring MVC project. I am including some jar files/packages in my project to convert DNS lookup.
I am getting console Outputs (System.out.println()) which is written in jar file.It is the status of my DNS conversions.
Some of the final outputs I show in UI through Model Attribbute
I need To show that console messages which is printed from a jar file in my GUI. How can I do this? Any Idea ?
I would go with SLF4J to clean up all your logging. Something like the below link should work and you can re-direct any other logging (log4j, commons-io ect) using the other slf4j logging dependencies.
http://projects.lidalia.org.uk/sysout-over-slf4j/quickstart.html

How do I configure log4j logging for a jar?

I have a project A with log4j.jar on its build path. I have a number of classes that have logging statements in the form of:
Logger _log = Logger.getLogger(A.<>.class);
...
_log.info("...");
I am exporting the project as a jar into another project B. Project B already has its own log4j jar and it's own .xml configuration file. I want to configure particular classes from A to log to Console Apender at varying "levels". How do I do this, please?
Well, basically, you shouldn't do that. Think of it this way: if that would be done that way, each library that is included in any application would host its own logging configuration, very potentially overriding any of those that are in the application, and each other, in non-specified order. You wouldn't want that. So do not.
[In case you really, really want to do it, you could have properties file in the jar that could be overriden by an xml file in the main application. See details here. But don't. :) ]
In general, you don't. In general, you want to have one log4j configuration file. But i suppose you could load your configuration explicitly from your code, as described in the log4j documentation
Pick a version of log4j.jar, probably the newer one. You can only use one version. You need to merge project A's and project B's logging configuration. You could do this in log4j classes at runtime, but don't. Just bite the bullet and merge them once in source control.

How to disable jackrabbit.log_IS_UNDEFINED in jackrabbit-standalone-2.4.2.jar

I have created a code using jackrabbit-standalone-2.4.2.jar and i am getting jackrabbit.log_IS_UNDEFINED.log file in the project directory. This log file is very huge(close to 1 GB). I want to disable it but i dont know how. Does anybody have any idea to deal with situation?
To remove this file you have to (as stated in the file name) to define the logger that you want to use.
Since jackrabbit is relying on slf4j, you should configure properly a logger for it.
For instance you can add to you dependencies the lf4j-log4j12 implementation, plus a log4j.properties in your classpath.
You can also configure any other slf4j implementation.
I have solved this issue by removing logback.xml and slf4j.jar from jackrabbit-standalone.jar and adding slf4j.jar and slf4j-lo4j.jar in the classpath of the project. Now jackrabbit.log_IS_UNDEFINED.log is gone and i am getting desired logs :)

Categories