I'm using Eclipselink JPA provider, and noticed that it writes in console only.
I configured both the console and file appenders, but EclipseLink log entries (SQL queries for example) are appeared only in the console log.
How to fix it?
Here is my log4j configuration:
log4j.rootLogger=ALL, FILE, CONSOLE
log4j.logger.uk.co.mycompany=DEBUG
log4j.logger.org.eclipse.persistence=ALL
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=${catalina.base}/logs/application.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{HH:mm:ss, SSS} %t [%p] %c{1} - %m%n
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
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} [%p] %m%ne
In the persistence.xml:
...
<properties>
<property name="eclipselink.logging.level" value="FINE"/>
</properties>
Eclipse Link doesn't use log4j by default. This page describes how you can integrate it:
http://wiki.eclipse.org/EclipseLink/Foundation/Logging
See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging
Make sure you initialize EclipseLink logging facilities (by doing some action that normally requires logging) before you add your own handlers to the system. I think that EclipseLink overrides the root logger settings and maybe destroys your configuration.
If you are using EclipseLink with JBoss AS7 i recommend Step 5: Configure EclipseLink logging (optional) in the following page on how to get logging correct:
https://community.jboss.org/wiki/HowToUseEclipseLinkWithAS7
In short you will need to:
Add JBossLogger.java file to you project (attached to the article)
Add dependency to library jboss-logging
Set property eclipselink.logging.logger in persistence.xml
Related
I'm testing my ear application on the container and I need to see some debugging messages I spread on my application. I'm using slf4j-api with log4j as logging framework.
During my test phase (out of the container) all logging was working perfectly, so the configuration is fine. But now I've deployed the application with the same configuration but my messages are not showing. Here is my log4j's config:
#rootLogger config
log4j.rootLogger=INFO, console
#appender config
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console..threshold=DEBUG
log4j.appender.console.target=System.out
log4j.appender.console.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.console.layout.ConversionPattern=%d{ABSOLUTE} [%t] %p %l - %m%n
# Log JDBC bind parameter runtime arguments
log4j.logger.org.hibernate.type=INFO
#application logger config
log4j.logger.ar.edu.unt.sigea=DEBUG, console
As I said, when I run my #Test methods, all my logger.debug() messages are shown correctly, but now that I'm running on the container with the same configuration, no debug message is shown.
I found this post and added the line log4j.appender.console..threshold=DEBUG as suggested by the answer but didn't work.
I'm deploying on Wildfly-10.0.0.Final Application Server and I'm using this logging dependencies:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
What am I missing? Where should I look for? Thanks in advance for your answers
You don't need to use the log4j binding unless you want to use your own log4j configuration. From the configuration file it looks like you're just using console appender which is already provided by the WildFly logging subsystem.
All you need to do to see debug messages with your current configuration is to remove the log4j.properties from your deployment and remove the org.slf4j:slf4j-log4j12 dependency from your pom. Then you can use the logging subsystem to configure logging and turn on/off debug logging. If you use CLI or the web console you can change logging levels without restarting the server.
To add a debug level and change the default console-handler level to DEBUG. The following two CLI commands are all you need to configure debug logging.
/subsystem=logging/logger=ar.edu.unt.sigea:add(level=DEBUG)
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=level, value=DEBUG)
looking at this Wildfly Documentation I realized that my log4j.properties file was located in a wrong place: it was in a submodule of my project and must be in the META-INF folder of the EAR module.
By default, Wildfly takes the deployment's logging configuration, so no extra configuration is needed in standalone.xml (or standalone-full.xml depending on what profile are you using, which is my case).
switch the log level to DEBUG on console
{wildfly}/bin/jboss-cli.sh --connect
[standalone#localhost:9990 /] /subsystem=logging/console-handler=CONSOLE:write-attribute(name=level,value=DEBUG)
[standalone#localhost:9990 /] /subsystem=logging/root-logger=ROOT:write-attribute(name=level,value=DEBUG)
switch it back to whatever it was initial configuration (here it is INFO)
[standalone#localhost:9990 /] /subsystem=logging/console-handler=CONSOLE:write-attribute(name=level,value=INFO)
[standalone#localhost:9990 /] /subsystem=logging/root-logger=ROOT:write-attribute(name=level,value=INFO)
From: https://gist.github.com/lfryc/aae879ceb5534292e150
I use flyway clean and migration during tests and flyway print on my screen a lot of INFO. I don't want to see that, because it makes tests unclear. How can i turn off INFO log ONLY for flyway?
Solution based on https://stackoverflow.com/a/22371427/5277820:
You have to add Log4J JAR to your classpath.
Also you have to create a log4j.properties file like this:
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 [%t] %-5p %c- %m%n
log4j.logger.org.flywaydb=WARN
and add it to your classpath.
For more information read the Log4J Manual.
Since version 3.1 Flyway supports also SLF4J, see Issue 834.
Thank your for your hints. What i exactly needed was:
(ns foo.fixtures
(:import (java.util.logging Logger Level)))
(.setLevel (Logger/getLogger "org.flywaydb") Level/WARNING)
(defn wrap-test [tests]
(reset-db)
(tests))
It turn off INFO logs for flyway only in tests without any additional dependency.
I am developing a web application which among the other uses the apache HttpClient to make some httpRequest.
For logging I am using slf4j with the slf4j-log4j12 'plug in'
What I want is to have DEBUG log level for my application but WARN level for the HttpClient. I am seeting the logging properties in log4j.properties.
log4j.rootLogger=DEBUG,console,file
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log.log
log4j.appender.file.threshold=DEBUG
The initialization and logging is like that
import org.slf4j.LoggerFactory;
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(<MY_CLASS>.class.getName());
LOG.debug("This is debug info");
LOG.warn("This is warn info");
Until now I am setting the following to the class that uses HttpClient
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
In order to 'deactivate' logging, but this stops the logging completely and does not set the level to WARN as I want.
Until now I have tried what is proposed on the following SO questions but with no luck. I have also seen many other which suggest pretty much the same.
Disable HttpClient logging
Logs are filling up with httpclient.wire.content dumps. How can I turn it off?
Passing parameters on execution such as java -Dlog4j is not a solution for me.
As a sidenote my project has two modules,
The 'parent module' defines the logging properties and has the slf4j (1.7.5) and slf4j-log4j12 dependencies
The child module is where I am using the HttpClient (4.3.4), it has only the
slf4j (1.7.5) dependency
Try adding these three lines to your log4j.properties file:
log4j.logger.org.apache.http=WARN
log4j.logger.org.apache.http.headers=WARN
log4j.logger.org.apache.http.wire=WARN
I'm trying to figure out why our Hibernate code is not logging anything to log4j. I put together a simple project that calls one Hibernate service method that logs a log4j message as the first line.
Both the project and the Hibernate service have the following log4j specific code:
private static Logger NTEVENT_LOG = Logger.getLogger("NTEVENT");
NTEVENT_LOG.debug("==== LOG4J logging");
When I run the project (Eclipse->run) I get the following messages in red:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
But immediately after I see the logging from the application itself so some part of log4j did get correctly initialized. However, nothing is being logged by the Hibernate service.
[main] DEBUG NTEVENT - ==== LOG4J logging
This is my log4j.xml
<appender name="NTEVENT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n"/>
</layout>
</appender>
<root>
<priority value ="debug" />
<appender-ref ref="NTEVENT" />
</root>
I must be missing something that Hibernate is expecting but I have no idea what.
To configure log4j using xml file you need to use DOMConfigurator.configure() method in your main.
Also for this method you need to import org.apache.log4j.xml.DOMConfigurator package.
public static void main(String[] args) {
DOMConfigurator.configure("log4j.xml");
..//your code
..
}
Hope this helps..!!
The problem was as ThrashBean implied, logging for org.hibernate was not enabled. If you want to see Hibernate debugging output, queries for instance, you need:
I finally got what was happening in my case. It might also help those in Netbeans users facing the same problem coz i have lost a lot of hair for quite some months now. My application had just stopped logging to console so i couldnt debug since the errors were not being displayed.
The answer "There are two log4j jar files in you libraries at different location." was true. Initially i had expected to find 2 files with the name log4xxx.jar of course with different version numbers but no file like that at all was there. You see Netbeans comes prepackaged with Hibernate libraries and many other libraries of course. So when developing in hibernate applications in Netbeans you DON'T need to manually add your own Hibernate Jars unless of course you need a specific version etc, you can just add the Hibernate library to your application via that right click project - Properties - Libraries - Add Library button . This will add many hibernate Jars in the background/classpath when running and also on Compiling in the dist/lib folder BUT NOT in the lib of the application. In my case i had added both the Hibernate Library AND also copied the generated hibernate jars from dist/lib to lib. This had happened by mistake as i copied libraries from previous application to include in my new application for use there.
So take home point, if in Netbeans, go to your lib folder, if you see jars like
hibernate-commons-annotations-x.x.x.Final.jar, hibernate-core-x.x.x.Final.jar,hibernate-entitymanager-x.x.x.Final.jar, hibernate-jpa-2.0-api-x.x.x.Final.jar, hibernate-tools-x.x.x.CR1.jar
Remove them and check if error resolves.
I build a REST web service (using JAX-RS, Spring, Spring JMS, and ActiveMQ). I'm surprised that when I deploy it to Tomcat 5.5.23 I get an exception that JSF jars are required?!
Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3712)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
The web service was working fine until I added log4j functionality in different classes, here's my log4j.properties file (I placed it in WEB-INF/classes):
log4j.rootCategory=INFO, S
log4j.logger.com.dappit.Dapper.parser=ERROR
log4j.logger.org.w3c.tidy=FATAL
#------------------------------------------------------------------------------
#
# The following properties configure the console (stdout) appender.
# See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.S = org.apache.log4j.ConsoleAppender
log4j.appender.S.layout = org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
Any idea how to resolve this?
I would expect to see this if you have a reference to org.apache.myfaces.webapp.StartupServletContextListener in your web.xml, like:
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
Can you verify that there is no such element?
Sounds like a classloader hierarchy issue. You should enclose log4j in your WAR file, not put it in the shared libraries of Tomcat.
Also, I had some problems with Tomcat 5.5 that was fixed in Tomcat 6.0. You may want to consider upgrading.
Make the following dependencies(if present) in maven as provided:
javax javaee-api 6.0 scope : provided
javax.servlet javax.servlet-api 3.0.1 scope : provided