Tomcat logging configuration - java

I am using Tomcat 7 / 8 in cloud, in panel log viewer got below log files:
Log files
Catalina.out
instance.log
access log
And i found official document from tomcat, but still confused.
https://tomcat.apache.org/tomcat-7.0-doc/logging.html
I cannot access such folder like /apache/apache-tomcat-8.0.15/logs
Can explain the usage for each log file with sample words?

In simple words:
Catalina.out - Some app logs and system specific logs
instance.log - Application specific logs
access log - Contains the app paths that were accessed (the users' Web requests)
More details / bg:
Catalina.out : "When running Tomcat on unixes, the console output is usually redirected to the file named catalina.out", so your System.out.println, logger.info, or exception should be found in it.
instance.log : the log related to application running status / life cycle.
There are two main approaches to configure Tomcat logs:
a. The java.util.logging (JUL) API
found at ${catalina.base}/conf/logging.properties
b. Apache log4j
found at $CATALINA_BASE/lib/log4j.properties. Don't confuse this with application's logs.
log4j.jar and log4j.properties go into WEB-INF/lib and WEB-INF/classes, respectively, in your web application.

Related

configure spring loggers with respect to application for multi module deployment

Spring framework logs are not logged as per the application specific log files in a multi module war files deployment
This is on a tomcat server, I have deployed 4 war files , and each log file needs to write the application specific logs into their respective application log file and not to a common log file .Lets say
1. app A --> A.log
2. app B --> B.log and so on.
log4j xml config which is used
I use log4j appenders and the application is segragted based on package name as highlighted below
Expected result : A.log file must have all the logs {including the spring framework/aop/rest template of that particular application}
Actual result: A.log file only has application based logger, all the spring framework logs are not logged into A.log, instead it logs into catalina.log

Why is the WildFly console log hijacking my WAR's log4j log?

I have 7 different WARs deployed to the same WildFly / JBoss server. Each WAR is identical in core design and Log4j configuration. Each WAR generates its own log file via its own individual custom log4j.xml. Each log is written to an individual folders.
1 of the 7 deployed WARs keeps getting the logging hijacked by WildFly's console.log. It will begin writing to its own log for 5-10 lines during initialization, then stop; the rest of the logging will be directed to the console.log.
If I re-install the WAR after this happens, it will write to both its own individual log and the WildFly console.log. If I restart WildFly, it will behave as described previously - begin logging to its own log, then continue on console.log.
The only thing unique about this WAR vs the other 6 is that this project uses JAXB; none of the other WARs use JAXB.
Is there some sort of unknown interaction between JAXB and Log4j and WildFly that might be causing this? I suspect, but cannot yet prove, the hijack is happening after the classes using JAXB are loaded by the ClassLoader.
jboss-7.2.0.Final , jdk-7u80x64, Log4j-1.2.13.jar
You may need to try move the logging.properties file to the WAR/WEB-INF/classes. I guess old Jboss EAP 6.4, There may have been a bug where it fails to look in the WAR/WEB-INF directory.
If that doesn't work you have to turn on trace logging for org.jboss.as.logging which should show the logging.properties file is found in your deployment.
The following CLI command will enable trace logging to see the details of what the logging subsystem is doing.
/subsystem=logging/logger=org.jboss.as.logging:add(level=TRACE)
If you want to see these log messages on the console you'll need to enable trace logging for the console tool.
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=level, value=TRACE)
resources:
sect-per-deployment_logging
Logging Configuration
Solved by excluding the log4j module from the application via /WEB-INF/jboss-deployment-structure.xml
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>

How to create my own logging configuration for an Openfire Plugin

I have the following setup
Version: Openfire 4.0.2
Server Directory: /opt/openfire
Running on a Centos (6) machine.
I have a plugin and I run a lot of debug code when developing. I will get an instance of a Logger using:
private static final Logger Log = LoggerFactory.getLogger(Submitter.class)
but the problem is that when I look at the logs (DEBUG level), I get EVERYTHING that has DEBUG (for example the httpd Apache libraries). I know that in JBOSS (and other systems) I can make a config that allows me to put Log Ouput of just my plugin to a specific location (e.g. a separate file).
Does anyone have any idea how to do this or if this is possible in Openfire?
Many thanks
In Openfire installation, under lib directory, there's a config file named
log4j.xml
just modify this and override default one.
If you need a log4j tutorial, check out at: https://www.mkyong.com/logging/log4j-xml-example
In you case you can:
redirect your own classes in another custom file
redirect all debug in another file and keep your custom class in
default debug log so it will be viable by Openfire webinterface

How to specify log4j.xml with aync

My Tomcat log4j.xml has a dependency on graylog2 server.
Few days back, my graylog2 server down due to storage issue after that my Tomcat's stop responding in between production hour. Then I came to know my log4j.xml has sync method that store the log first to graylo console then catalina.
How to come out with this dependecy?

Tomcat App says "Unable to configure the logging system. No log.properties was found."

I have an embedded tomcat app and whenever I start it up I see this error printed to the console twice:
Unable to configure the logging system. No log.properties was found.
It seems stupid, but I've done some googling and searched stackoverflow and can't seem to find someone experiencing this problem.
My main class Looks roughly like this:
public class AuthServerEntryPoint {
static {
org.apache.log4j.PropertyConfigurator.configure("conf/log4j.properties");
}
public static void main(String[] args) {
// ...
}
"conf/log4j.properties" contains a seemingly valid configuration:
log4j.appender.mainAppend=org.apache.log4j.ConsoleAppender
log4j.appender.mainAppend.layout=org.apache.log4j.PatternLayout
log4j.appender.mainAppend.layout.ConversionPattern=%d %p [%t] %c -- %m%n
log4j.appender.fileAppend=org.apache.log4j.FileAppender
log4j.appender.fileAppend.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppend.layout.ConversionPattern=%d %p [%t] %c - %m%n
log4j.appender.fileAppend.file=logs/myservice.log
log4j.rootLogger = info, fileAppend
log4j.logger.com.mycompany.myservice = debug, fileAppend
And the logging actually does work - i.e., logs are correctly written to myservice.log. So what gives?
Thanks!
-Carl
By embedded Tomcat app, do you mean that you are starting Tomcat from Java code and are using the class org.apache.catalina.startup.Embedded?
If yes, my guess is that Tomcat might not be able to find its logging configuration file that is set up in catalina.sh (or equivalent) when using the scripts:
LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
The odd part is that this file is called logging.properties, not log.properties, so I'm really not sure. I didn't check Tomcat sources though, maybe they are doing some kind of black magic in there.
Could you just try to rename $CATALINA_BASE/conf/logging.properties into log.properties (or not) and to put it on the classpath of your app (or to set -Djava.util.logging.config.file)?
By default, log4j will look for a logging properties file on the classpath. Put your webapp's logging properties config file into its WEB-INF/classes directory; e.g.
$CATALINA_HOME/webapps/<yourApp>/WEB-INF/classes/log4j.properties
This is the simple approach to getting a webapp to use Log4j is recommended by the referenced documentation. And it is the approach I use myself for webapp logging.
There are various other ways to configure Log4j logging on Tomcat as well. It is possible that your Tomcat has been (partly) configured to use one of them, but something has not been done quite right.
Configuring Tomcat' log4j logging via the system properties is an option that avoids figuring out where log4j is looking ... and what is going wrong. But you are then stuck with creating/using a custom launch script or having to remember to set environment variables before launching Tomcat.
References:
Configuring logging on Tomcat 5.5
Configuring logging on Tomcat 6
The "Default Initialization under Tomcat" section of the Log4j Manual

Categories