JCL logging in Glassfish via SLF4j - java

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.

Related

ERROR StatusLogger Log4j2 could not find a logging implementation. But i am not using any logger

When I run my project I get this error :
ERROR StatusLogger Log4j2 could not find a logging implementation.
Please add log4j-core to the classpath. Using SimpleLogger to log to
the console...
The thing is I am not using Log4j anywhere in my project. I don't have it in my pom.xml, I don't use it or import it in any of my class, so why do I have this error message?
Here is a screen of what i get when i search for "log" in my whole project :
As you can see, no use of any logger.
I don't know what other information I can provide so feel free to ask.
EDIT : I've already tried this

How to setup ebean log level with log4j

I'm using log4j and slf4j-log4j12 to print log in my project.
Problem is i don't want to show ebean's log.
I have read Ebean logging config documentation but it's for logback.
I have tried log4j.logger.io.ebeaninternal.server.transaction.JdbcTransaction=INFO. It's not work too.
Does anyone know how to config log4j for ebean to just printout [INFO] level or None
I solved my problem. This is my config for anyone who need it.
# Setup log level for Ebean
log4j.logger.io.ebean.SQL=INFO
log4j.logger.io.ebean.SUM=INFO
log4j.logger.io.ebean.TXN=INFO
log4j.logger.org.avaje.classpath.scanner=INFO

Log4j2 properties | monitorInterval not working

I am using log4j 2.4 and trying to convert log4j2.xml to log4j.properties, however monitorInterval property doesn't seem to be working with log4j2.properties.
status = trace
name=PropertiesConfig
property.filename = logs
appenders = console, file
monitorInterval=10
though log4j2 following documentation
https://logging.apache.org/log4j/2.x/manual/configuration.html#Properties
clearly stats that
Properties configuration files support the advertiser,
monitorInterval, name, packages, shutdownHook, status
any changes in property file doesn't leads to reloading of logging configuration. On the contrary, it seems to be perfectly working in xml format
<Configuration status="TRACE" monitorInterval="5">
where whenever I do make any changes in .xml my log4j configuration is picked up and is verified via following log.
2016-06-17 14:43:17,267 Thread-5 DEBUG Reconfiguration started for context 1198108795 (org.apache.logging.log4j.core.LoggerContext#86be70a)
2016-06-17 14:43:17,268 Thread-5 DEBUG Not in a ServletContext environment, thus not loading WebLookup plugin.
2016-06-17 14:43:17,273 Thread-5 DEBUG Initializing configuration XmlConfiguration[location=/Users/userx/Desktop/logs/log4j2_prod.xml]
I also tried to upgrade Log4j version to 2.5 but still observe same behavior.
To add to Ralph's answer, this was fixed in Log4j 2.6. The corresponding ticket is https://issues.apache.org/jira/browse/LOG4J2-1263
Please use Log4j-2.6.1 or later.
This was a bug that has been fixed. I would suggest updating the latest log4j release.

Dropwizard application not using log config from configuration.yml

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>

View Logger output in eclipse for a java project

in one of my elicpse project I have come across this logger related snippet, I noticed that it is from slf4j library.
private static final Logger logger = LoggerFactory
.getLogger(someclass.class);
Then in some point of the code i noticed this,
logger.debug("Found {} object",
numberofobject);
My question is, when I run the program I do not see the logger output, how can I see that in eclipse?
You need to properly configure the binding for slf4j. slf4j is just a facade, not a logging tool.
Since 1.6.0 if no binding is found on the class path, then SLF4J will default to a no-operation implementation.
Have a look at the officiel manual here on how to configure slf4j.
you need to add a logging library to your project that implements the slf (just as Burkhard mentioned)
You need to configure the logger of your choice to log debug messages to the console (e.g. with a console appender in log4j)

Categories

Resources