How to Debug / Log Tomcat JDBC Connection Pool’s connections?

After a lot of research, I am able to find 3 ways to log & monitor database connection pool. https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html Monitoring using Spring Boot properties. Monitoring using JMX ( Java Management Extensions ) (as @nitin suggested) Monitoring using Spring Aspects. 1st Way: Monitoring using Spring Boot properties. I found below Spring boot properties which will … Read more

How to exclude a single Class from a Log4j Logger / Appender?

Simply configure your fifth class to use the log-level OFF: log4j.logger.com.example=INFO, MyAppender log4j.logger.com.example.FifthClass=OFF Actually I suggest you don’t set it to OFF, but to FATAL. ERROR or even WARN instead. The main reason to want to ignore logging from some class is usually if it logs to much (more than is useful and makes it … Read more

Is it possible to reload log4j.xml / log4j.properties file dynamically in Tomcat?

From http://logging.apache.org/log4j/1.2/faq.html#3.6 Is there a way to get log4j to automatically reload a configuration file if it changes? Yes. Both the DOMConfigurator and the PropertyConfigurator support automatic reloading through the configureAndWatch method. See the API documentation for more details. Because the configureAndWatch launches a separate wathdog thread, and because there is no way to stop … Read more

file and stdout appenders in logback.xml

Try this: <configuration> <appender name=”FILE” class=”ch.qos.logback.core.FileAppender”> <file>${user.home}/database.log</file> <append>false</append> <encoder> <pattern>%-5relative %-5level %logger{35} – %msg%n</pattern> </encoder> </appender> <appender name=”STDOUT” class=”ch.qos.logback.core.ConsoleAppender”> <encoder> <pattern>%-5relative %-5level %logger{35} – %msg%n</pattern> </encoder> </appender> <logger name=”jdbc” level=”OFF” /> <logger name=”jdbc.sqlonly” level=”INFO” additivity=”false”> <appender-ref ref=”FILE” /> </logger> <root level=”ERROR”> <appender-ref ref=”STDOUT” /> </root> </configuration>

Log4J: How do I redirect an OutputStream or Writer to logger’s writer(s)?

My suggestion is, why dont you write your OutputStream then?! I was about to write one for you, but I found this good example on the net, check it out! LogOutputStream.java /* * Jacareto Copyright (c) 2002-2005 * Applied Computer Science Research Group, Darmstadt University of * Technology, Institute of Mathematics & Computer Science, * … Read more

Log4j 2.0 and SLF4J and the never ending future of java logging frameworks [closed]

Disclaimer: I am the founder of log4j, slf4j and logback projects but unaffiliated with log4j 2.0. As I understand it, notwithstanding its name, log4j 2.0 is very different than log4j 1.x. As far as the user API is concerned, log4j 2.0 is largely incompatible with log4j 1.x. Log4j 2.0 provides an adaptation layer for log4j … Read more

Log4j formatting: Is it possible to truncate stacktraces?

You can use a EnhancedPatternLayout in log4j to format your stacktraces. See http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html, specifically the section about the “throwable” pattern in the pattern table. Note that support for the %throwable{n} support is rather new and requires at least log4j 1.2.16 (which is the latest at time of writing) For tracking purposes, this is the ticket … Read more

Compress Log4j files

log4j extras has support for that. Just add the following to your RollingFileAppender configuration and have the filename end in .gz to automagically compress your log files: <appender…> <rollingPolicy class=”org.apache.log4j.rolling.TimeBasedRollingPolicy”> <param name=”FileNamePattern” value=”/wombat/foo.%d{yyyy-MM}.gz”/> </rollingPolicy> </appender> For more details check the Javadoc