Update - this problem was of my own doing.
At one stage this particular test class had a test to ensure that something was logged. In the setup, I had previously removed all appenders and added my own appender for making test-time assertions. That test is long since gone, but this nugget remained in the setup: Logger.getRootLogger().removeAllAppenders();.
Sorry for the false alarm. :)
In IDEA I have the following test:
#Test
public void shouldLog() {
URL resource = Thread.currentThread().getContextClassLoader()
.getResource("log4j.properties");
System.out.println("resource = " + resource);
final Logger logger = Logger.getLogger(getClass());
logger.info("Hello world");
}
It outputs thusly:
"C:\Program Files\Java\jdk1.5.0_18\bin\java" -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 11.1\lib\idea_rt.jar" -ea -Dfile.encoding=UTF-8 com.intellij.rt.execution.CommandLineWrapper C:\DOCUME~1\JMAWSO~1.NT3\LOCALS~1\Temp\classpath2294205410661538428.tmp #vm_params C:\DOCUME~1\JMAWSO~1.NT3\LOCALS~1\Temp\vm_params5645362020129462784.tmp com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 au.com.gmm.repo.RepoThreadCleanupServiceTest,shouldLog
resource = file:/C:/user/jem/projects/GMM/out/test/cashflow/log4j.properties
log4j:WARN No appenders could be found for logger (au.com.gmm.repo.RepoThreadCleanupServiceTest).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Process finished with exit code 0
This is a famous problem, seen by many newbies over and over again. I feel a little silly being stumped by it today.
http://logging.apache.org/log4j/1.2/faq.html#noconfig says log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files. However, my test checks Thread.currentThread().getContextClassLoader().getResource("log4j.properties") and finds the properties file with no problem.
The content of the file is:
log4j.rootLogger=DEBUG, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss.SSS} %c - %m%n
I am using log4j with slf4j in IntelliJ IDEA and it works perfectly for me. Just include these jars into your application dependencies in IntelliJ:
log4j-1.2.9.jar
slf4j-api-1.5.11.jar
slf4j-log4j12-1.5.11.jar
Than put somewhere in your app the log4j configuration. But DO NOT forget to mark that location of the log4j.properties in IntelliJ as Sources or if you using it on tests as Test Sources:
log4j.properties:
log4j.rootLogger=INFO,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} - %m%n
log4j.logger.your.app=DEBUG,yourApp
log4j.additivity.your.app=false
log4j.logger.yourApp=DEBUG,yourApp
log4j.additivity.yourApp=false
log4j.appender.yourApp=org.apache.log4j.ConsoleAppender
log4j.appender.yourApp.layout=org.apache.log4j.PatternLayout
log4j.appender.yourApp.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} %m%n
log4j.appender.yourApp.ImmediateFlush=true
Then in your java class use this to get the logger:
private static final Logger LOGGER = LoggerFactory.getLogger(YourApp.class);
And you will not see any of warnings like: No appenders could be found for logger.
Hope this helps.
Related
Recently I started getting bad class file during build in IntelliJ IDEA 2021.2.2 and MapStruct version 1.4.2.Final. Maven build is running fine. Does anyone have a clue? Thanks a lot!!
Intellij compiler logs:
DEBUG - s.incremental.java.JavaBuilder - java:ERROR:Internal error in the mapping processor: com.sun.tools.javac.jvm.ClassReader$BadClassFile: bad class file: Please remove or make sure it appears in the correct subdirectory of the classpath.
at com.sun.tools.javac.jvm.ClassReader.badClassFile(ClassReader.java:357)
at com.sun.tools.javac.jvm.ClassReader.readEnclosingMethodAttr(ClassReader.java:1276)
at com.sun.tools.javac.jvm.ClassReader$12.read(ClassReader.java:1130)
at com.sun.tools.javac.jvm.ClassReader.readAttrs(ClassReader.java:1381)
at com.sun.tools.javac.jvm.ClassReader.readClassAttrs(ClassReader.java:1396)
at com.sun.tools.javac.jvm.ClassReader.readClass(ClassReader.java:2226)
at com.sun.tools.javac.jvm.ClassReader.readClassFile(ClassReader.java:2324)
at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:2511)
at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:2442)
at com.sun.tools.javac.jvm.ClassReader.access$000(ClassReader.java:76)
at com.sun.tools.javac.jvm.ClassReader$1.complete(ClassReader.java:240)
at com.sun.tools.javac.code.Symbol.complete(Symbol.java:574)
at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1037)
at com.sun.tools.javac.code.Symbol$ClassSymbol.flags(Symbol.java:973)
at com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:734)
at javax.lang.model.util.ElementScanner6.visitPackage(ElementScanner6.java:167)
at com.sun.tools.javac.code.Symbol$PackageSymbol.accept(Symbol.java:901)
at com.sun.tools.javac.processing.JavacRoundEnvironment$AnnotationSetScanner.scan(JavacRoundEnvironment.java:158)
at com.sun.tools.javac.processing.JavacRoundEnvironment$AnnotationSetScanner.scan(JavacRoundEnvironment.java:127)
at com.sun.tools.javac.processing.JavacRoundEnvironment.getElementsAnnotatedWith(JavacRoundEnvironment.java:121)
at org.mapstruct.ap.MappingProcessor.getMappers(MappingProcessor.java:235)
at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:165)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:802)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:713)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1043)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1184)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
I use cucumber testNG for my project and and already added some configuration based on Configuring BDD for execution and QAF Cucumber but when i run it, GherkinScenarioFactory not run any test.
[main] ERROR com.qmetry.qaf.automation.util.PropertyUtil - resources\application.properties (The system cannot find the path specified)
[main] INFO com.qmetry.qaf.automation.core.ConfigurationManager - ISFW build info: {qaf-Type=core, qaf-Revision=15, qaf-Version=2.1, qaf-Build-Time=20-N
ov-2019 22:28:06}
[main] ERROR com.qmetry.qaf.automation.core.ConfigurationManager - D:\Automation\resources not exist!
include groups []
exclude groups: [] Scanarios location: resources/features
[main] INFO com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory - scenario.file.loc[Ljava.lang.String;#400cff1a
[main] INFO com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory - total test found: 0
I've added the dependency qaf and also qaf-cucumber with version 2.1.15. I've also added the #QAFTestStepProvider annotation in the step file. Here's my testng.xml file :
<suite name="MyTest">
<test name="ComparationTest" >
<parameter name="step.provider.pkg" value="com.example.steps" />
<parameter name="scenario.file.loc" value="resources/features" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
in the feature file I added : Examples: {'datafile': 'resources/data/data.xls'}
and last in cucumber runner I added plugin "com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin"
I'm still learing, can somebody tell me what did i miss?
It looks that you are pointing to wrong location for resources and feature file/directory. You need to provide relative path to project root directory for resources and scenarios directory. If you observe the log also complains that fie/folder not exist.
[main] ERROR com.qmetry.qaf.automation.util.PropertyUtil - resources\application.properties (The system cannot find the path specified)
[main] INFO com.qmetry.qaf.automation.core.ConfigurationManager - ISFW build info: {qaf-Type=core, qaf-Revision=15, qaf-Version=2.1, qaf-Build-Time=20-N
ov-2019 22:28:06}
[main] ERROR com.qmetry.qaf.automation.core.ConfigurationManager - D:\Automation\resources not exist!
Make sure that you have resources directory under project root.
Regarding feature files, according to your current configuration
scenario.file.loc is resources/features. In that case make sure that <project-root>/resources/features is exist. For example your project root is D:/Automation then resources/features points to D:/Automation//resources/features
If not then provide correct relative path to project root.
For example resources/features expects <project-root>/resources/features if it is not there provide correct location.
Same is applied for other resources including properties file and test data files.
For application.properties it is expected under <project_root>\resources\application.properties if it is not there you can provide location by using system property application.properties=<relateive_path_to_project> or alternately place under default location <project_root>\resources.
As a side note,
instead of GherkinScenarioFactory recommended is BDD2 factory com.qmetry.qaf.automation.step.client.text.BDDTestFactory2
Latest version of qaf as of today is 3.1.0-RC1 the version you are using 2.1.15 is quite old.
I have set the default test lifecycle to per_class for a project using JUnit5. This is done in the junit-platform.properties file. However, since applying this configuration, my test runs are now preceded by a lot of logging output:
Dec 06, 2018 8:15:22 PM org.junit.platform.launcher.core.LauncherConfigurationParameters fromClasspathResource
INFO: Loading JUnit Platform configuration parameters from classpath resource [file:/Users/amb85/Projects/kotlin/katas/out/test/resources/junit-platform.properties].
Dec 06, 2018 8:15:22 PM org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils getDefaultTestInstanceLifecycle
INFO: Using default test instance lifecycle mode 'PER_CLASS' set via the 'junit.jupiter.testinstance.lifecycle.default' configuration parameter.
I don't want to see these log messages. How do I disable them or set the log level higher?
Found an answer in:
https://github.com/junit-team/junit5/issues/1774#issuecomment-463662553
Summarizing:
Set 'java.util.logging.config.file' system property pointing to a logging.properties file that reduces the log level.
tasks.withType(Test).configureEach {
useJUnitPlatform()
systemProperty 'java.util.logging.config.file', "${project.buildDir}/resources/test/logging-test.properties"
testLogging {
showStandardStreams = true
}
}
logging-test.properties:
handlers=java.util.logging.ConsoleHandler
.level=INFO
org.junit.platform.launcher.core.LauncherConfigurationParameters.level=WARNING
org.junit.jupiter.engine.config.EnumConfigurationParameterConverter.level=WARNING
I'm also having the same issue. A possible solution may be to intercept the default JUnit5 logger (java.util.logging.LogManager) and discard that INFO log. I have not yet implemented it, but you are not alone with this.
Here's some links from my research:
https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-instance-lifecycle-changing-default
https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-interfaces-and-default-methods
I downloaded Ignite 2.5.0 (I use maven dependences in Eclipse on a Mac for my Java class), and I tried to start Ignite with a configuration file given with an absolute path:
public static void main(String [] args) throws Exception {
try (Ignite ignite = Ignition.start("/Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml")) {}
}
but I got exception:
Exception in thread "main" class org.apache.ignite.IgniteException: Failed to find configuration in: file:/Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml
at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:990)
at org.apache.ignite.Ignition.start(Ignition.java:355)
at hu.sztaki.lpds.ml.ignite.WekaIgnite.main(WekaIgnite.java:82)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to find configuration in: file:/Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:116)
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:98)
at org.apache.ignite.internal.IgnitionEx.loadConfigurations(IgnitionEx.java:744)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:945)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:854)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:724)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:693)
at org.apache.ignite.Ignition.start(Ignition.java:352)
... 1 more
The config file is there:
$ cat /Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml
<?xml version="1.0" encoding="UTF-8"?>...
and:
new File("/Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml").exists() is true
According to docs this path can be absolute.
What am I doing wrong?
Thank you.
I think, the problem is that default-config.xml file has only abstract IgniteConfiguration. This is the case in the default configuration file in examples.
Check, if the configuration bean's definition has abstract=true parameter, and remove it if it does.
P.S.
Creating Ignite as a resource of a try block is a pretty bad idea, since the node will stop right after execution of the try block is finished.
Hello I am trying to connect a Java Maven application to Cassandra with hector. The code is very simple
imports......
public class App {
public static void main( String[] args ){
Cluster cluster = HFactory.getOrCreateCluster("TestCluster",
new CassandraHostConfigurator("localhost:9042"));
}
}
}
When I run it I have these exceptions:
log4j:WARN No appenders could be found for logger (me.prettyprint.cassandra.connection.CassandraHostRetryService).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
I think I need to set up something but I cannot find what it is.
You need a log4j properties file. From the Hector docs:
Run your application with the following parameter:
-Dlog4j.configuration=file:///path/to/log4j.properties
Where log4j.properties contains:
log4j.rootLogger=DEBUG,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
Log4J is very powerful, check out the project site for more information.