Why is Log4j2 throwing an error in Windows bash console - java

Good morning,
using log4j2 in my project (see below the configuration) running it, everything went ok in Eclipse. Then building the jar and executing it in a bash Windows, I get an error thrown regarding the "Console Appender". After investigation, it works in other shells (like git bash), my question here is about if this behavior is documented somewhere ?(because after googling it a lot, I did not find anything relevant).
My log4j2.properties:
name=PropertiesConfig
property.directory = ./logs
appenders = console, file, testFile
appender.console.type = Console
appender.console.target =SYSTEM_OUT
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} line %L - %msg%n
appender.file.type = File
appender.file.append = false
appender.file.name = LOGFILE
appender.file.fileName=${directory}/neoswitcher-${date:yyyy-MM-dd-HH-mm-ss}.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.testFile.type = File
appender.testFile.append = false
appender.testFile.name = LOGTestFILE
appender.testFile.fileName=${directory}/test-suite-${date:yyyy-MM-dd-HH-mm-ss}.log
appender.testFile.layout.type=PatternLayout
appender.testFile.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
loggers=file
logger.file.name=org.test.controller.core
logger.file.level = info
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE
loggers=file
logger.testFile.name=org.simpleperftests.core;
logger.testFile.level = info
logger.testFile.appenderRefs = testFile
logger.testFile.appenderRef.file.ref = LOGTestFILE
rootLogger.level = info
rootLogger.appenderRefs = stdout, file, testFile
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.file.ref = LOGFILE
rootLogger.appenderRef.testFile.ref = LOGTestFILE
And here the error occuring in the MS-DOS console:
2017-02-24 10:55:11,994 main ERROR Unable to inject fields into builder class for plugin type class org.apache.logging.log4j.core.appender.ConsoleAppender, element Cons
ole. java.nio.charset.UnsupportedCharsetException: sun.stdout.encoding
at java.nio.charset.Charset.forName(Charset.java:531)
at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:146)
at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:134)
at org.apache.logging.log4j.core.appender.ConsoleAppender$Target.getCharset(ConsoleAppender.java:85)
at org.apache.logging.log4j.core.appender.ConsoleAppender$Target$1.getDefaultCharset(ConsoleAppender.java:71)
at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:218)
at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:185)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:551)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:537)
at org.test.controller.core.App.<clinit>(App.java:14)
2017-02-24 10:55:12,001 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.appender.ConsoleAppender for element Console. java.lang.
IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.ConsoleAppender
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:224)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:130)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:551)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:537)
at org.test.controller.core.App.<clinit>(App.java:14)
2017-02-24 10:55:12,012 main ERROR Null object returned for Console in Appenders.
2017-02-24 10:55:12,012 main ERROR Unable to locate appender "STDOUT" for logger config "root"
Edit: It actually works fine on Linux with that version

After testing with the snapshot release (version 2.8.1-SNAPSHOT), the bug is fixed.
The snapshot versions for log4j2 are available at this repository: https://repository.apache.org/content/repositories/snapshots/

Using version 2.8.1 instead of 2.8.0 seemed to resolved the issue for me
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>

I also had same issue in Windows command promt. I tried in Git Bash and it is working fine as usual.
So, install Git Bash and try in Git Bash, it should work fine.

Related

log4j:WARN No appenders could be found for logger (org.springframework.web.filter.CharacterEncodingFilter). with log4j2

I am in the process of migrating from log4j 1.2 to log4j 2.
I have my whole configuration into a log4j2.properties file.
I noticed that I got a new error message in my logs while starting my tomcat :
log4j:WARN No appenders could be found for logger (org.springframework.web.filter.CharacterEncodingFilter).
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 have verified with my previous logs, and I did not have this warning previously.
Here is my previous configuration (in the log4j.properties file):
log4j.rootLogger=INFO, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{dd-MM HH:mm:ss} %p %t %c - %m%n
log4j.logger.com.example=DEBUG
log4j.logger.org.springframework=INFO
Here is the new one (in log4j2.properties) :
appender.console.type = Console
appender.console.name = ConsoleAppender
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d %p %t %c - %m%n
loggers = log1, log2
logger.log1.name = org.springframework
logger.log1.level = INFO
logger.log1.appenderRef = ConsoleAppender
logger.log2.name = com.example
logger.log2.level = DEBUG
logger.log2.appenderRef = ConsoleAppender
rootLogger.level = ERROR
rootLogger.appenderRef.stdout.ref = ConsoleAppender
So, what I've understand so far is :
I create one appender, named ConsoleAppender, of type Console
I create two loggers that goes each onto ConsoleAppender, one on org.springframework (level INFO) and the other on com.example (level INFO)
I use this page to try to understand how to do the migration.
Do you see any explanation about why I should have this particular message ?
As seen in this answer, the issue may be due to the fact that I was also using slf4j-log4j12 (but in the latest version already) and it was in conflict with other log4j apis :
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
So I did what's told and I removed the org.slf4j:slf4j-log4j12 dependancy and added log4j-api & log4j-slf4j-impl dependancies :
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8.2</version>
</dependency>
... and for know it seems to solve the error (it doesn't appear anymore into my starting logs
To be more clear, I first only added the three above dependancies without removing the slf4j-log4j12 one, and I got this as well into the logs :
SLF4J: Found binding in
[jar:file:/myuser/apache-tomcat-7.0.75/webapps/mywebapp/WEB-INF/lib/log4j-slf4j-impl-2.8.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/myuser/apache-tomcat-7.0.75/webapps/mywebapp/WEB-INF/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
After having removed the slf4j-log4j12 dependancy, the whole error logs disappeared.

ClearNLP (NLP4J) parser Error Execute

I'm trying to train with ClearParser and I get this error. Before execute the command I put export CLASSPATH=nlp4j-1.1.0.jar:. and doing java edu.emory.mathcs.nlp.bin.Version I get the version info, so it's installed correctly.
Command line: java -Xmx5g -XX:+UseConcMarkSweepGC edu.emory.mathcs.nlp.bin.NLPTrain -mode dep -c config-train-dep.xml -t /home/iago/Escritorio/idiomasClearParser/UD_English/en-ud-train.conllu -d /home/iago/Escritorio/idiomasClearParser/UD_English/en-ud-dev.conllu -m bestModel-dep.xz
I'm using this config file: https://github.com/emorynlp/nlp4j/blob/master/src/main/resources/edu/emory/mathcs/nlp/configuration/config-train-dep.xml
Error: log4j:WARN No appenders could be found for logger (edu.emory.mathcs.nlp.common.util.BinUtils). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. java.io.FileNotFoundException: edu/emory/mathcs/nlp/lexica/en-brown-clusters-simplified-lowercase.xz (No existe el archivo o el directorio) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.<init>(FileInputStream.java:138) at java.io.FileInputStream.<init>(FileInputStream.java:93) at edu.emory.mathcs.nlp.common.util.IOUtils.createFileInputStream(IOUtils.java:147) at edu.emory.mathcs.nlp.common.util.IOUtils.getInputStream(IOUtils.java:316) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.getLexiconFieldPair(GlobalLexica.java:82) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.getLexiconFieldPair(GlobalLexica.java:72) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.<init>(GlobalLexica.java:64) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.<init>(GlobalLexica.java:55) at edu.emory.mathcs.nlp.bin.NLPTrain$1.createGlobalLexica(NLPTrain.java:108) at edu.emory.mathcs.nlp.component.template.train.OnlineTrainer.train(OnlineTrainer.java:193) at edu.emory.mathcs.nlp.component.template.train.OnlineTrainer.train(OnlineTrainer.java:187) at edu.emory.mathcs.nlp.bin.NLPTrain.train(NLPTrain.java:76) at edu.emory.mathcs.nlp.bin.NLPTrain.main(NLPTrain.java:115) java.io.IOException: Stream closed at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:159) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) at java.io.BufferedInputStream.read(BufferedInputStream.java:345) at java.io.DataInputStream.readFully(DataInputStream.java:195) at java.io.DataInputStream.readFully(DataInputStream.java:169) at org.tukaani.xz.SingleXZInputStream.initialize(Unknown Source) at org.tukaani.xz.SingleXZInputStream.<init>(Unknown Source) at org.tukaani.xz.XZInputStream.<init>(Unknown Source) at org.tukaani.xz.XZInputStream.<init>(Unknown Source) at edu.emory.mathcs.nlp.common.util.IOUtils.createXZBufferedInputStream(IOUtils.java:220) at edu.emory.mathcs.nlp.common.util.IOUtils.createObjectXZBufferedInputStream(IOUtils.java:259) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.getLexiconFieldPair(GlobalLexica.java:82) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.getLexiconFieldPair(GlobalLexica.java:72) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.<init>(GlobalLexica.java:64) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.<init>(GlobalLexica.java:55) at edu.emory.mathcs.nlp.bin.NLPTrain$1.createGlobalLexica(NLPTrain.java:108) at edu.emory.mathcs.nlp.component.template.train.OnlineTrainer.train(OnlineTrainer.java:193) at edu.emory.mathcs.nlp.component.template.train.OnlineTrainer.train(OnlineTrainer.java:187) at edu.emory.mathcs.nlp.bin.NLPTrain.train(NLPTrain.java:76) at edu.emory.mathcs.nlp.bin.NLPTrain.main(NLPTrain.java:115) Exception in thread "main" java.lang.NullPointerException at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2338) at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2351) at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2822) at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:804) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:301) at edu.emory.mathcs.nlp.common.util.IOUtils.createObjectXZBufferedInputStream(IOUtils.java:259) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.getLexiconFieldPair(GlobalLexica.java:82) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.getLexiconFieldPair(GlobalLexica.java:72) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.<init>(GlobalLexica.java:64) at edu.emory.mathcs.nlp.component.template.util.GlobalLexica.<init>(GlobalLexica.java:55) at edu.emory.mathcs.nlp.bin.NLPTrain$1.createGlobalLexica(NLPTrain.java:108) at edu.emory.mathcs.nlp.component.template.train.OnlineTrainer.train(OnlineTrainer.java:193) at edu.emory.mathcs.nlp.component.template.train.OnlineTrainer.train(OnlineTrainer.java:187) at edu.emory.mathcs.nlp.bin.NLPTrain.train(NLPTrain.java:76) at edu.emory.mathcs.nlp.bin.NLPTrain.main(NLPTrain.java:115)
Why I'm getting this error? I unpacked the .jar and there is no "lexica" folder neither "en-brown-clusters-simplified-lowercase.xz". Where I can found it?
Regards
I found the solution, this error happens because you don't have the "log4j.properties" configured so "nlp4j" can't find it. To fix it only create the file on the same folder that the .jar with this simple code (if you want more details adapt it to your needs)
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File= /path/to/file
log4j.appender.file.MaxFileSize=5MB #Set what you need
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Moreover, to solve the problem of lexica. Go to this url and download the jars lexica url
Then, on the config xml set the correct path to the jars.
And now it should works. Hope it helps someone.

How to add log4j to a web application in java

I am trying to add log4j to my web application to record the exchange between the server and the client so I added the dependency in my pom.xml:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
and I created the log4j.proporties:
# Root logger option
log4j.rootLogger=INFO, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
#Redirect to Tomcat logs folder
#log4j.appender.file.File=${catalina.home}/logs/logging.log
log4j.appender.file.File=C:\\test.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%
and the following is my code :
static final Logger logger = Logger.getLogger(hellologger.class);
public static void main(String[] args) {
String log4JPropertyFile = "C:\\Users\\xxxx\\Desktop\\log4j.properties";
Properties p = new Properties();
try {
p.load(new FileInputStream(log4JPropertyFile));
PropertyConfigurator.configure(p);
logger.info("Wow! I'm configured!");
} catch (IOException e) {
}
}
But finally I got this error :
Infos: org.osgi.framework.BundleException: Unresolved constraint in bundle com.mycompany.webclient [329]: Unable to resolve 329.7: missing requirement [329.7] osgi.wiring.package; (&(osgi.wiring.package=org.apache.log4j)(version>=1.2.0)(!(version>=2.0.0)))
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:1175)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:1153)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.processAllBundles(DirectoryWatcher.java:1146)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:456)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:263)
any idea how to fix this problem ?!!!!
You can go through this tutorial on log4j .
The properties file and pom.xml files are explained properly .
logs generated are like this :
2014-07-02 20:52:39 DEBUG HelloExample:19 - This is debug : mkyong
2014-07-02 20:52:39 INFO HelloExample:23 - This is info : mkyong
2014-07-02 20:52:39 WARN HelloExample:26 - This is warn : mkyong
2014-07-02 20:52:39 ERROR HelloExample:27 - This is error : mkyong
2014-07-02 20:52:39 FATAL HelloExample:28 - This is fatal : mkyong

How to use log4j in RCP application with Maven?

I am working on a small RCP project which has Maven nature and now I wish to add log4j dependencies with that.
For that purpose what I did was :
Added log4j.properties under bin folder inside the project. bin is the folder where all the class files are getting generated. The file looks like this:
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\Srijani\\Personal Workspace\\RCP\\EditorApp\\log\\Application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Added this dependency in pom.xml
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
In java code I wrote like this:
import org.apache.log4j.Logger;
import com.app.editor.constants.Constants;
public class DatabaseConnection {
final static Logger logger = Logger.getLogger(DatabaseConnection.class);
}
This code does not creata any problem while compiling. But, while running the code, I got this error:
!ENTRY org.eclipse.e4.ui.workbench 4 0 2016-01-13 13:50:35.397
!MESSAGE Unable to create class 'org.eclipse.ui.internal.e4.compatibility.CompatibilityView' from bundle '55'
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:62)
Note: I did not add anything to MANIFEST.MF and build.properties.
Please help!
Thanks
Update: Got the issue but not sure how to solve it. When I am downloading the jar manually and set it in the class path, I am able to use log4j in Eclipse RCP. But, when I am trying download it via Maven, it is not working. Any idea why this is happening?
If you use Maven in combination with Eclipse RCP you should consider using Tycho[1]. Tycho uses the MANIFEST-first approach, so that you don't need to edit the pom-files.
In addition you should put your log4j.properties into a fragment with the log4j-bundle as host-plugin.
[1] https://eclipse.org/tycho/
I hope in this website explained clearly. It will helps to you.
http://www.mkyong.com/logging/log4j-hello-world-example/
My sincere suggestion is, before implement in project try to create one sample example. If it success, you can apply same into project.

log4j with spring doesn't work

In my pom.xml, I've added a dependency for using Log4j
pom.xml
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
</dependency>
Then, I executed the following command
mvn clean install
After this command, I notice that the log4j-1.2.9.jar is well added in my lib directory itself in the target directory
Then, I started the google app engine server with the following command in my project :
appengine:devserver
And my log4j.properties in src/main/resources
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
After, by opening the jar file in winzip, I noticed that the Logger.class was in org/apache/log4j directory, so, when I tried to import the Logger class in a java file, it didn't detect the package 'log4j'.
Do you have any solutions ?
Thank you

Categories

Resources