Need to disable log4j output to console during jUnit tests running but all other log4j output should be enable. There are lot exceptions during testing while checking method reaction on incorrect argument, so exception is ok.
Create a new log4j properties file called e.g. log4j-test.properties with logging disabled. In your surefire config in the POM, add argLine with -Dlog4j.configuration=log4j-test.properties.
I know this question is quite old, but still relevant in my opinion, so I'll add an alternative answer.
If you just want to disable (or reduce) logging for certain tests, or for some reason want to do it from code rather than creating a config file, you could do the following:
RootLogger.getRootLogger().setLevel(Level.OFF);
Related
Consider you have a Spring-Boot Application and within this application also a bunch of Integration-Tests, which are annotated with #SpringBootTest and run with the SpringRunner class.
They are invoked by the maven failsafe plugin, which by default does not parallelise tests in any way. The tests all run fine without any issues.
What changes if you use failsafe's feature of forkCount - can you expect the test execution to work out of the box? Do you need to adjust some code? What do you need to look out for that could potentially not allow these integration tests to run in a forked, "parallel" environment via this plugin?
From my understanding, the failsafe plugin will create forkCount-many JVMs and in each some of the integration tests are executed. That sounds like there is nothing to do, you don't need to make anything threadsafe, you don't need to make Singleton-beans into ThreadScoped beans or anything - as the process of having multiple JVM's should already create multiple of these beans.
Sorry if the question appears weird, I tried researching this question but I could not find an answer.
From Maven doc:
The parameter forkCount defines the maximum number of JVM processes
This means that the tests will run in it's own process and therefore you will have separate Spring Boot instances. So you really don't have to care about thread safety.
But you have to care about memory consumption.
I would like to reduce the footprint of a fat springboot jar file.
The answer to this question actually covers everything Developing spring boot application with lower footprint
We need to include only the dependencies that we need and do not use auto configuration
My question is:
1- is there anyway (e.g. a script) to list the only used dependencies in a springboot project. i am actually doing trial and error to see if i need a dependency or not.
2- is there anyway to list the AutoConfiguration classes that i have to exclude, i can go and debug to see what springboot is auto configuring and pickup what i dont need, however i am looking for something like a script to check the code and give me a list of the AutoConfiguration classes that i have to exclude.
Gradle is used for dependency management.
If you are using Gradle you can see the full dependency list in a very good and interactive way via command gradle --scan then you can exclude some of the repeated ones.
I am writing a spring-batch application, based on an example I found. When I run it in Eclipse, it produces some annoying INFO logs from deep inside the framework. I'd like to suppress that, so only my System.out statements show - for clarity.
I figured the logging is from the inherited commons-logging1.1.1.jar, that's in my classpath, because when I take out that reference I get errors about Logger.
Question1: Which framework is used for logging in my sample application and how can I change the default INFO to WARN?
Question2: will adopting Log4j just override this default behavior?
I've create two property files under /resources: commons-logging.properties, with this: org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog, and simplelog.properties, with this: org.apache.commons.logging.simplelog.defaultlog=warn It worked. Thanks - –
Never worked with log4j before, that's why I may ask some stupid questions.
I got a multi-module Maven Web Application that runs on Glassfish 3.1.
Every module is more or less independent.
Well, I set up the log4j configurations (log4j.properties), put it in the Dist "module" config folder. Also, every pom.xml of every module has a log4j dependency. Added the classpaths. Also, added in the domain.xml the jvm option, referencing the log4j.property:
<jvm-options>-Dlog4j.configuration=file:///${com.sun.aas.instanceRoot}/log4j.properties</jvm-options>
In the Glassfish Admin panel, i added Configuration option referencing to the log4j.properties file (Configuration -> severf-config -> JVM General Settings -> JVM Options).
-Dlog4j.configuration=file:///${com.sun.aas.instanceRoot}/log4j.properties
I found This stuff out reading a lot on the Internet about log4j.
So, now my problem is that when I start the Maven Build, the build executes the Unit Test, and the framework works just fine, ut it doesn't log any activity from the application. What could it be?
Does every module needs its own log4j.property (I guess not, because it's logging already entries from methods called from the unit test from modules that don't have the log4j.propertie).
Is it possible that the log4j has to bi initialized before/during the start of the application?
Again, it logs unit test and maven build, but not during runtime, that's what I don't get. Am I missing something?
The solution was to put the log4j.properties file into the persist Maven module (src/main/resources).
Now, it logs the activities..
I am having problems integrating perf4j in an existing maven application.
I tried several approaches, but none of them seemed to work, so I was wondering if anyone has some insight into how this is done.
What I want to do is use the AOP part of perf4j on some methods and log them into a different file than the one used for app logging. Thanks
You might be suffering from the same declaration order issue as mentioned in another perf4j/logback related question. In short, it is always a good idea to enable printing of logback's internal status messages by setting the debug attribute to true within the configuration element. Also do not forget that any referenced appender must be declared beforehand.