SLF4J-LOG4J logging without a log4j.properties file on Tomcat - spring-boot

I hope you can solve this very mysterious puzzle!
After migrating to Java8 and Tomcat8, the logging info on the servers is ok, but there is no logging information on the developer laptops. Adding Spring-boot-starter-log4j2 there is logging info on the laptops but NOT on the servers. How come? How to fix?
In the parent.pom both the dependencies slf4j-api, the slf4j-log4j binding and the 'slf4j : jcl-over-slf4j' are used. In the project there are no log4j.properites files. In all places where spring boot is used, the spring-boot-starter-logging is excluded.
Scenario 1:
On laptops - the SLF4J combination produces NO logging. I guess that is because there are no log4j.properties files. On the servers this combination shows logging. How can this be? Can there be a provided Tomcat configuration that allows this logging?
Scenario 2:
When I add the spring-boot-starter-log4j2, then I get logging on my laptop. On the server there is no logging at all.

You can define general logging settings in your tomcat environment. This is for example shown in this article.
In short: (1) add an extra library and (2) add a default log4j.properties file.

Related

How to Enable DEBUG log level in Spring MVC 4

I have a simple spring MCV application (spring-webmvc 5.0.6) and when running I can see the logs are printing.
My question is how to enable Debug log level. Currently I haven't add and log4j property file but I can see the logs are printing in INFO level.
I tried to find answers to this simple question, so far was not able.
My pom.xml file dependency section has following dependencies.
spring-webmvc (5.0.6.RELEASE)
servlet-api (2.5)
jstl (1.2)
Any help with this would be appreciated.
Since you said that you didn´t provide a logging-implementation, Springs variant of Commons Logging API will only find Java.util.logging (JUL) from the JDK (see Spring Documentation)
By the way: Level.DEBUG in Terms of JUL would be Level.FINE or Level.FINER (see this Articel Log Levels)
Assuming that your app is running on a Tomcat-Server you might edit one of the following files to see Level.FINE on the Console:
Just add:
java.util.ConsoleHandler.level=FINE
org.springframework.level=FINE
${java.home}/lib/logging.properties (global loggin-properties of JRE)
${catalina.base}/conf/logging.properties (global logging-properties of Tomcat)
WEB-INF/classes/logging.properties (webapp-specific logging-properties)

How to turn of hibernate-validator DEBUG logger

I add hibernate-validator(6.0.9.Final) to my spring (not spring boot) maven project and work perfectly, but cause lot of(~3000 row) DEBUG log. How to off this log?
I tried these, but didn't work:
logging.level.org.hibernate=info
log4j.logger.org.hibernate=info
The log level of Hibernate Validator is (obviously) not DEBUG by default so you must have something in your application classpath setting the log level to DEBUG.
Hibernate Validator is using JBoss Logging which uses log4j under the hood so log4j.logger.org.hibernate.validator=info in your log4j.properties should work.
But considering it shouldn't have been set to DEBUG in the first place, I'm wondering if you have something in your classpath overriding your log configuration.
I suspect either you or a dependency have enabled DEBUG logging for org.hibernate to see the queries or something similar and this is this setting you should find and remove.
Set the log4j properties as
log4j.logger.org.hibernate.validator=info
also set the show_sql =false to avoid the query printing on the console.

Log4j configuration on Glassfish3.1, only Unit Test logging

Never worked with log4j before, that's why I may ask some stupid questions.
I got a multi-module Maven Web Application that runs on Glassfish 3.1.
Every module is more or less independent.
Well, I set up the log4j configurations (log4j.properties), put it in the Dist "module" config folder. Also, every pom.xml of every module has a log4j dependency. Added the classpaths. Also, added in the domain.xml the jvm option, referencing the log4j.property:
<jvm-options>-Dlog4j.configuration=file:///${com.sun.aas.instanceRoot}/log4j.properties</jvm-options>
In the Glassfish Admin panel, i added Configuration option referencing to the log4j.properties file (Configuration -> severf-config -> JVM General Settings -> JVM Options).
-Dlog4j.configuration=file:///${com.sun.aas.instanceRoot}/log4j.properties
I found This stuff out reading a lot on the Internet about log4j.
So, now my problem is that when I start the Maven Build, the build executes the Unit Test, and the framework works just fine, ut it doesn't log any activity from the application. What could it be?
Does every module needs its own log4j.property (I guess not, because it's logging already entries from methods called from the unit test from modules that don't have the log4j.propertie).
Is it possible that the log4j has to bi initialized before/during the start of the application?
Again, it logs unit test and maven build, but not during runtime, that's what I don't get. Am I missing something?
The solution was to put the log4j.properties file into the persist Maven module (src/main/resources).
Now, it logs the activities..

Websphere Configuration to Avoid Unwated Warnings in SystemOut.log File

I have a problem about logging in SystemOut.log with Websphere. Can someone help me?
I’m getting some unwanted warning written in the SystemOut.log file with Websphere Application Server (WAS). All of the warnings are being generated by OGNL (ognl.NoSuchPropertyException). These exceptions don’t affect the code flow. Hence I need to turn off the logging of these warnings.
Also I have configuration in log4j.properties file to control the filtration of the log messages to error.
It would be a great help if anyone can help what configuration I should do in WAS to avoid logging these warnings.
Regards
You can change the log level from WAS admin console. Servers->WAS->servername->troubleshooting->change log details level
Follow the path and you will see options to filter warning. For example to filer message from com.ibm.ws.*=WARN will filter all but WARN.
Hope this helps.
First, you have to determine what running component, inside your WAS instance, is generating these warning messages. Is it WebSphere itself, logging these warnings internally? or is it your code?
If the source is WebSphere, then perhaps, before setting the logging level to "error" or "severe", you may want to open a PMR with IBM. I never encountered OGNL warnings generated by WebSphere itself. These warnings, then, can be indicative of a problem in your WebSphere installation.
If the source is your application, then the way to cope with this situation depends on how OGNL, internally, is generating these messages:
If OGNL is simply writing log lines to System.out, then there's nothing you can do to suppress these lines.
If OGNL is logging through Log4J, then you should be able to set the log level of the OGNL logger(s) through your log4j.properties. If your log4j.properties changes aren't reflected, then it means that you have a classloading problem of some sort (the log4j.properties file being loaded by a different classloader than the one used to load your web application).
If OGNL is using a different logging framework (such as SLF4J or Commons Logging), then you'll have to read through the documentation of these frameworks to learn how to tune the logging level.

liberty profile control logging

I cannot control logging levels for my code in Websphere Liberty Profile server.
I have configured the server.xml on the server not to log hibernate and spring, since my logs will get flooded with activity from those two frameworks. I commonly do this using log4j and it works fine in standalone WAS.
<logging consoleLogLevel="INFO" copySystemStreams="true" traceFormat="ENHANCED" traceSpecification="org.springframework.*=off:com.ibm.ws.*=off:org.hibernate*=off"/>
In Liberty this does not work.
I get the following log when liberty updates the configuration (when I save server.xml with the changes):
[INFO ] TRAS0040I: The configured trace state included the following specifications that do not match any loggers currently registered in the server: org.hibernate*=off:org.springframework.*=off
Basically this message applies to any of my code and any third party code (Spring, Hibernate, etc).
However the traceSpecification levels work fine for the IBM classes, and I'm able to specify *=off, which effectively turns off all logging.
Has anyone experienced this?
IBM's documentation for TRAS0040I seems simple enough, but I can't seem to figure out why my loggers are not getting registered with the server.
Liberty doesn't have a rich control on logging. You should understand the difference between "logging" and "tracing". Check description of console.log, messages.log, trace.log files at the beggining of: http://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/rwlp_logging.html
Your configuration in "traceSpecification" - actually will do nothing, as spring and hibernate are logs from JVM and they doesn't go to trace, so trace configuration doesn't affect them.
All you can configure in liberty for jvm logs is consoleLogLevel (INFO, AUDIT, WARNING, ERROR, and OFF)
If you want to configure log levels for specific components in Liberty - you should use for example log4j with own configuration

Resources