Wildfly 10 not showing debug messages - java

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

Related

Why explode log file excluding spring-boot-starter-logging?

I deployed a war project in a Tomcat and it works without any problem. So I tried to deploy same war project in another tomcat. To deploy in this new Tomcat I need to insert this exclusion in my pom.xml file:
spring-boot-starter-logging
this exclusion get a lot of log lines ... inserting exclusion I have a log line every 30 seconds. This is the log line :
2019-10-02 11:36:08 DEBUG HikariPool:404 - ProjectHikaryPool - Pool stats (total=10, active=0, idle=10, waiting=0)
Image
spring-boot-starter-logging is embedded in the spring boot starter web. Spring boot is not dedicated to a specific logging framework and the default one is logback as you can read in the docs. Enabeling the spring-boot-starter-logging or spring-boot-starter-web will print out all the system side debug information to the console. If you disable it the logs won't be printed. Why don't you expect this behaviour?
If you want to change the log level that is printed to the console you can use
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
for example as mentioned in the docs

Set apache HttpClient log level explicitly

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

How to write logs to a file using Log4j and Storm Framework?

I am having bit of an issue in logging to a file using log4j in storm .
Before submitting my topology , i.e in my main method I wrote some log statements and configured the logger using :
PropertyConfigurator.configure(myLog4jProperties)
Now when I run my topology using my executable jar in eclipse -
its working fine and log files are being created as supposed.
OR
When i run my executable jar using "java -jar MyJarFile
someOtherOptions", i can see log4j being configured and the files are
formed correctly and logging is done on both files and console (as
defined in my log4j.properties)
BUT when i run the same jar using "storm jar MyJarFile MyMainClass someOtherOptions" it is not being able to create and log
into any of the files except on console.
I am talking about the logs I am printing BEFORE submitting my topology.
Is there any way to log my statements in a file while using storm ? I am not bound to use org.apache.log4j.
The storm framework uses its own logging. Your logs most likely will end up in the logs dir where storm is installed({Storm DIR}/logs). You can find the storm log properties in {Storm DIR}/logback/cluster.xml. It uses logback not log4j
I would recommend using SLF4J for your logging within storm. You probably could get LOG4J working but you will have additional setup to do on each node in the cluster. Since storm does this for you already, I don't really see the point.
In your project, include these maven dependencies (slf4j-simple for your unit tests!):
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
<scope>test</scope>
</dependency>
Then, inside your topologies/spouts/bolts you just get the Logger:
private static final Logger LOG = LoggerFactory.getLogger(MySpout.class);
In my environment, anything INFO and above is logged to file and, more importantly, visible in the Storm UI. You just need to click on your spout/bolt and then click on the port number to go to the log viewer page.
If you want to get to the actual files then you can gather them off of each node (mine are in /var/log/storm/).

Logging from Spring using Log4j under WebSphere

I'm using log4j in my WebSphere application. I need to debug class org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor, so I've created logger in my log4j.xml file:
<logger name="org.springframework">
<level value="INFO" />
</logger>
<logger name="org.springframework.ejb.access">
<level value="TRACE" />
</logger>
I've created also commons-logging.properties in src/main/resources of the web project (in maven):
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
However, Spring is NOT logging using log4j. I see no springframework logs in my debug file, but I can see some of them (INFO) in the console. Therefore I assume, the apache commons logging used by Spring is NOT logging using log4j.
Is it possible (and how) to redirect logging used by Spring to Log4j engine under WebSphere?
WebSphere 7.0, Spring 3.1.2, log4j 1.2.6, commons-logging 1.1 provided in shared library.
Try the following:
Consider using slf4j for your logging. Add log4j to your dependencies in maven.
Add jcl-over-slf4j to your maven dependencies. This redirectes each request from jcl to slf4j.
Search for the dependency commons-logging inside your maven dependencies. Exclude it, so it does not get to your deployment archive.
Delete the "commons-logging.properties"-file.
I hope that everythings works out fine now.
This technique to route JCL (including Spring) logging to your log4j configuration still works.
For the apps where we also have slf4j already (the Spring WebFlow ones), that can also be routed to your log4j configuration.
However, if you just want to see the Spring log information, you can increase its level of logging to WebSphere's own logs (SystemOut.log) via the console's Troubleshooting > Logs and Trace > server-name > Change log level details.
Add something like : org.springframework.ejb.access.*=fine (colon is the separator).
I don't know what the exact WAS levels correspond to, but fine, finer, and finest are listed under the "Trace" levels if you expand the Components and Groups area just to see what is available.
(I don't think it matters that your particular Spring package is not listed under there, BTW. I believe it should still successfully control your logging.)

Disabling logging for jetty run from maven

I downloaded a big framework which I need to built from source. The project uses a maven build structure, and includes a demo application which can be viewed with an embedded jetty. Maven plugins handle all this stuff.
However when I run the demo application (with mvn jetty:run), I can't really use it because for some reason logging on the DEBUG level is turned on and the application spends most of its time logging a lot of statements. Responsiveness is reduced to almost nothing.
The framework (geomajas 1.5.0) seems to use SLF4J, but I can't figure out where it is configured or where it can be turned off.
Any ideas welcome... thanks!
Update:
Apparently they use logback. I found the configuration file (logback.xml), in which I edited out the DEBUG levels and replaced them with ERROR
To make sure the changes would propagate, I cleaned the project and rebuilt it. But the issue remains!
I manually looked at the logback.xml files in the target folder, and they've updated. But I still see the log records!
Update 2
I'm on Windows 7 btw.
The simplest and most straight forward way to disable logging would be indeed to use the NOP binding. To do so, edit geomajas/geomajas-dojo-example/pom.xml and change the logging dependencies into:
<!-- logging dependencies, delegate all to slf4j and use logback -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.5.8</version>
</dependency>
And run mvn jetty:run.
looking at this slf4j manual/overview http://www.slf4j.org/manual.html it looks like you could turn off all logging by using the slf4j NOP jar (slf4j-nop-1.5.10.jar). So you'd probably need to find and replace the current slf4j implementation jar in your projects WEB-INF/lib folder with the NOP jar.
Though most likely it's using a log4j implementation, if that's the case you'd need to find the log4j.xml or log4j.properties and edit/remove them. They could be tricky to find though - first look in WEB-INF/classes and then in some sort of config directory would be a good start.
EDIT {
A bit ugly but if you just want to get it up and running as fast as possible you could redirect stdout and stderr to /dev/null which should make it a bit faster as it won't be writing to disk or console:
mvn jetty:run > dev/null 2>&1
}
HTH
Try to find out a log4j configuration (if it is used for logging) - that might be log4j.xml (or log4j.properties) file. If you remove this file from classpath there will be no logging at all. If you want to reduce level of logs try to comment out some logger sections in this file, like e.g.
<!--<logger name="org.hibernate">
<level value="debug"/>
<appender-ref ref="hibernate-file"/>
</logger>-->
For this example there will be no logs for classes from org.hibernate package.
Geomajas uses logback for the sample applications. You can configure the logging using the logback.xml file in src/main/resources.
Switching everything off can be done using a config file like:
<configuration>
<root>
<level value="OFF"/>
</root>
</configuration>
Kind regards,
Joachim

Categories

Resources