I'm trying to use SLF4J with log4j in a Bean inside a EJB, I have already tried to place the log4j.properties file in quite a few places but I keep getting this error in the Glassfish Server console:
Grave: log4j:WARN No appenders could be found for logger (uy.ort.enviosya.cadets.services.CadetsBean).
Grave: log4j:WARN Please initialize the log4j system properly.
Grave: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info
This is my properties file:
# LOG4J configuration
log4j.rootLogger=DEBUG, Appender1,Appender2
log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
log4j.appender.Appender2=org.apache.log4j.FileAppender
log4j.appender.Appender2.File=C:/Users/Log4jWebDemo.log
log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
The questions related to this problem say I should place it in the classpath but honestly I don't know what they mean by that (totally new to EJB).
This is what I'm doing in the bean:
@Stateless
public class SomeBean implements SomeBeanRemote {
private static final Logger LOGGER = LoggerFactory.getLogger(SomeBean.class);
@Override
public someMethod() {
LOGGER.info("Prueba");
...
}
...
}
Plus, should I be placing the file inside the EJB? What if I want to modify the destination of the Appender2
then?
I'm using Netbeans 8.2.
Update 1
I have placed it inside the META-INF
folder of my ejb, and from what I can see it is present in that same folder in the Cadets-ejb.jar
that I'm deploying inside .ear
.
But I'm still getting the same error.
Partial folder structure:
Some
build
Some-ejb
build
dist
nbproject
src
conf
META-INF
java
test
dist
lib
nbproject
src
Update 2
I managed to get it working but by placing the properties file by hand in the correct place in the build folder, which means I need to do this every time I do a clean-build.
I tried placing it in the src folder but when I build it doesn't get copied, only what is inside src/conf
gets copied and that is the wrong location for this file.
Why is the file in src
being ignored on build?
This is my structure now:
Some
/build
/Some-ejb
/build
/dist
/nbproject
/src
/conf
/META-INF
MANIFEST.MF
/java
/log4j.properties
/test
/dist
/lib
/log4j.jar
/nbproject
/src
I now that the file, once the jar is created needs no be at the same level that META-INF
and my class packages.
Solution
I solved it by placing it here
Some
/build
/Some-ejb
/build
/dist
/nbproject
/src
/conf
/META-INF
MANIFEST.MF
/java
log4j.properties
/test
/dist
/lib
/log4j.jar
/nbproject
/src