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
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 trying to get DropWizard to log to an output file. The file is being created but nothing written to it.
In fact it would appear that the configuration in the provided .yml file is not being used.
I am also getting the following warnings during startup, not sure if they are related:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/conor/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/conor/.m2/repository/com/conor/project/project-common/0.1-SNAPSHOT/project-common-0.1-SNAPSHOT.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
How can I get dropwizard to pickup the logging config in the yml provided at startup and how can I figure out where the current config is coming from? Thanks.
UPDATE::
I am running DropWizard v0.9.1 and my logging configuration is as follows:
# Logging settings.
logging:
# The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
level: TRACE
# Logger-specific levels.
loggers:
# Sets the level for 'com.example.app' to DEBUG.
io.dropwizard: INFO
# Redirects SQL logs to a separate file
org.hibernate.SQL:
level: DEBUG
# Logback's Time Based Rolling Policy - archivedLogFilenamePattern: /tmp/application-%d{yyyy-MM-dd}.log.gz
# Logback's Size and Time Based Rolling Policy - archivedLogFilenamePattern: /tmp/application-%d{yyyy-MM-dd}-%i.log.gz
# Logback's Fixed Window Rolling Policy - archivedLogFilenamePattern: /tmp/application-%i.log.gz
appenders:
- type: console
- type: file
threshold: DEBUG
logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n"
currentLogFilename: output/logs/dropwizard.txt
archivedLogFilenamePattern: output/logs/dropwizard-%d{yyyy-MM-dd}-%i.txt.gz
archivedFileCount: 10
timeZone: UTC
maxFileSize: 10MB
This looks like a typical SLF4J binding issue and is solved easily. First take a look at the relevant section in the URL provided with the warning for an explanation.:
The warning emitted by SLF4J is just that, a warning. Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it. The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random. As of version 1.6.6, SLF4J will name the framework/implementation class it is actually bound to.
Embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose. When you come across an embedded component declaring a compile-time dependency on any SLF4J binding, please take the time to contact the authors of said component/library and kindly ask them to mend their ways.
Since the binding choice is random, my guess is that the project-common SLF4J dependency is being bound and not the intended one from logback-classic, a transitive dependency of dropwizard. You should either exclude the one in the project-common in your Maven pom file or better yet, if you have access to the code to project-common, remove it from the pom file as the linked-to web page suggests (i.e. "mend their ways").
From the Exception, I think you are using the two different version of logback classic both in class path which arise the conflicts. Try to find out the jar which are included two times but different version and remove one of them. If you are using the Maven to manage the dependency exclude the jar using the tag
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>the version you want to remove</version>
</exclusion>
</exclusions>
I'm trying to setup logging of application on Glassfish server. I use SLF4j to aggregate everything and Logback binding to write the files. Also I added log4j-over-slf4j, jul-to-slf4j and jcl-over-slf4j libraries to the project. Of course slf4j-api and Logback ones are there too. All the libraries are in project WEB-INF/lib and in glassfish/lib/endorsed.
So the idea is: redirect everything to SLF4j and then log with Logback.
In the code I have the following piece for test:
jclLog.debug("Login JCL: Debug level");
jclLog.error("Login JCL: Error level");
log4jLog.debug("Login Log4j: Debug level");
log4jLog.error("Login Log4j: Error level");
slfLog.debug("Login SLF4j: Debug level");
slfLog.error("Login SLF4j: Error level");
After execution there are log entries og Log4j and SLF4j in Logback-configured log files. But JCL entries are not there. They get to server.log file instead.
The question is: why JCL entries are catched with Glassfish logger and how could it be prevented?
You can't (yet) do this. See http://java.net/jira/browse/GLASSFISH-6666 for the relevant bug report.
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