My application is daily writing localhost-date.log and writing logs related with org.apache.catalina.core.ApplicationContext for example:
Jan 09, 2017 11:47:43 AM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Jan 09, 2017 11:47:43 AM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/web/contex/ContextCleanupListener
Here's my logging.properties tomcat config:
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter =java.util.logging.SimpleFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
# For example, set the com.xyz.foo logger to only log SEVERE
# messages:
#org.apache.catalina.startup.ContextConfig.level = FINE
#org.apache.catalina.startup.HostConfig.level = FINE
#org.apache.catalina.session.ManagerBase.level = FINE
#org.apache.catalina.core.AprLifecycleListener.level=FINE
I don't want any localhost log file instead of I want to write the above error in Catalina or Application log.
May I know how to do this?
In the Handler specific properties section you are defining 2 file handlers (1catalina and 2localhost).
In the Facility specific properties section you are setting the level .level and the handler .handler for each logger.
To remove the localhost.XXXX-XX-XX.log files and log to the catalina.XXXX-XX-XX.log file you have to do the following steps.
Remove (delete or comment in) the localhost file handler.
#2localhost.org.apache.juli.FileHandler.level = FINE
#2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
#2localhost.org.apache.juli.FileHandler.prefix = localhost.
Set the catalina file handler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 1catalina.org.apache.juli.FileHandler
Related
I have logrotate working perfectly, only thing is that when the log file is saved with the date at the end of the filename like: catalina.out-20180926. But there is nothing being logged to catalina.out.
Everything is owned by root, tomcat is running under root. I've restarted tomcat as a service and it restarts fine creating a new log file of the restart logs, then nothing is logged until I restart the service again.
My logging properties file looks like this;
handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler
# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE
# To see debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE
Any ideas?
After moving from SysV init scripts to the Systemd service units, Tomcat standard output and error streams are no longer logged to catalina.out. If you need to see stdout and stderr logs, you can find them in the journal:
journalctl -u tomcat
If you want to follow the Tomcat stdout+stderr log, you can use:
journalctl -f -u tomcat
See the last 100 lines:
journalctl -n100 -u tomcat
For more information, see systemd and journald documentation.
I currently have multiple web applications deployed in Tomcat which is running as a Windows service. I created/modified most of the logging.properties files to (hopefully) create a separate log file for each web application.
My conf\logging.properties looks like:
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
1catalina.org.apache.juli.AsyncFileHandler.level = FINE 1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
2localhost.org.apache.juli.AsyncFileHandler.level = FINE 2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
3manager.org.apache.juli.AsyncFileHandler.level = FINE 3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 3manager.org.apache.juli.AsyncFileHandler.prefix
= manager.
java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers
= 2localhost.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level
= INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers
= 3manager.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level
= INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers
= 4host-manager.org.apache.juli.AsyncFileHandler
# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE
# To see debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE
# To see debug messages for HTTP/2 handling, uncomment the following line:
#org.apache.coyote.http2.level = FINE
# To see debug messages for WebSocket handling, uncomment the following line:
#org.apache.tomcat.websocket.level = FINE
Each of my web apps has the following logging.properties file int he WEB-INF\classes folder:
handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
org.apache.juli.FileHandler.level = FINE
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
org.apache.juli.FileHandler.prefix = prefix.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
I am currently logging everything within my web applications on the INFO level like so:
Logger.getLogger("LOG").log(Level.INFO, "Stuff to log");
Things seem to be relatively close to how I was hoping. Stdout seems to be correctly going to the individual web application logs, but EVERYTHING also seems to be going to the tomcat8-stderr log as well.
I tried commenting out the ConsoleHandler from ALL config.properties, but I was still getting the same behavior. How do I prevent everything from also being logged in the stderr log?
I added this to my Context.xml, but that did not seem to change anything:
<Context swallowOutput="true">
I was able to fix this by setting the Level of my web application loggers to FINE and changing the web application ConsoleHandler level in logging.properties to INFO.
As documented in Official Tomcat site, the private package-renamed implementation of Apache Commons Logging namely JULI does have exceptions. the .handlers directive is defining the ROOT logger which in turn is the only possible output for calls that are coming directly from ClassLoader of common jars such as the StandardEngine ones or the java.sql driver ones. Unless a specific handler is assigned by class name after which a method call like java.util.logging.Logger.getLogger() could get potentially get a grip.
To use the so called "Facility specific properties" tomcat-juli features of per Engine, per Host and per Context log, the logging.properties in effect is the global tomcat logging configuration initially loaded at Engine startup :
The calls to javax.servlet.ServletContext.log(...) to write log
messages are handled by internal Tomcat logging. Such messages are
logged to the category named
org.apache.catalina.core.ContainerBase.[${engine}].[${host}].[${context}]
This logging is performed according to the Tomcat logging
configuration. You cannot overwrite it in a web application.
However,
JULI [...] supports per classloader configuration, in addition to the regular global java.util.logging configuration. This means that logging can be configured at the following layers:
Globally. That is usually done in the ${catalina.base}/conf/logging.properties file. The file is specified by the java.util.logging.config.file System property which is set by the startup scripts. If it is not readable or is not configured, the default is to use the ${java.home}/lib/logging.properties file in the JRE.
In the web application. The file will be WEB-INF/classes/logging.properties
So after making some various tests, I realized that I was not able to reproduce your issue, as I successfully logged from an application exclusively and entirely to the prefix.yyyy-mm-dd.log file defined in the per application WEB-INF/classes/logging.properties.
I say "entirely" taking into consideration that if the web application uses System.out.print(), the printed stuff will only show up in the "prefix."-files if swallowOutput is set to true in the context.xml (whether it be from the application's META-INF/context.xml or from the ${CATALINA_BASE}/conf/context.xml file.
Tweaking the logging levels to avoid the situation you where is not to my opinion an elegant bypass and I hope you have not settled down to that and will share your final resolution unless the problem vanished since !
In java.util.logging log configuration, I want to override the console log level specifically for some packages, how can I do that?
For example, I tried the configuration
handlers= java.util.logging.ConsoleHandler
.level= INFO
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
com.mypackage.MyClass.level= ALL
The MyClass log level being set to ALL, but it do not seem to log anything less than info on the console.
I think , you should give the log level at package level, not at the class level.
Try com.mypackage.level= ALL instead of com.mypackage.MyClass.level= ALL.
Also you can edit these settings by login to WAS admin console, under logs and traces.
I am using Eclipse to create (Session Bean + MDB), deployed in OpenEJB. It works. Now how can I output the log debug info to console ? I need to add a log4j.properties in the project or to change the OpenEJB server properties ?
Thanks.
You need to add log4j.properties to your classpath and add the following configuration to log the OPENEJB debug to the console.
log4j.category.OpenEJB = warn
log4j.category.OpenEJB.server = info
log4j.category.OpenEJB.startup = info
log4j.category.OpenEJB.startup.service = warn
log4j.category.OpenEJB.startup.config = info
log4j.category.OpenEJB.hsql = info
log4j.category.CORBA-Adapter = info
log4j.category.Transaction = warn
log4j.category.org.apache.activemq = error
log4j.category.org.apache.geronimo = error
log4j.category.openjpa = error
You can modify the logging by changing the Log Levels.
I'm using Hibernate for a personal project.
In my project, I have these directory:
+ conf
log4j.properties
+ bin
my classes
Using Windows console, I go to project directory (the parent of bin and conf) and I start the application with a command like this:
java -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main
My log4j.properties file is this (taken from an hibernate example):
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d - %m%n
log4j.rootLogger=info, stdout
log4j.logger.org.hibernate=error
log4j.logger.org.hibernate.tool.hbm2ddl=error
log4j.logger.org.hibernate.hql.ast.QueryTranslatorImpl=error
log4j.logger.org.hibernate.hql.ast.HqlSqlWalker=error
log4j.logger.org.hibernate.hql.ast.SqlGenerator=error
log4j.logger.org.hibernate.hql.ast.AST=error
On application start, this is the output:
2010-11-06 19:00:56,376 - Logger.getRootLogger().info() statement
12 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.3-Final
13 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
16 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
20 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
108 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: com/moc/hibernate.cfg.xml
108 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: com/moc/hibernate.cfg.xml
124 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from file: conf\hiber\Customer.hbm.xml
.
.
.
and so on
.
.
.
795 [main] INFO org.hibernate.impl.SessionFactoryImpl - closing
795 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:mysql://localhost/mydb
The color of Hibernate log lines is red, my log lines are black.
Why I still see INFO output from Hibernate? What am I doing wrong?
A good way of checking your log4j configuration and the events occuring at runtime is adding
-Dlog4j.debug option to the java command line. In your case it will become:
java -Dlog4j.debug -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main
This will throw information on console of the sequence of loading of log4j configuration. You can then determine if your log4j.properties is getting loaded correctly or not.
Your log4j configuration looks ok, is your log4j.properties file on the classpath and in the root package? I.e. is it in the root of conf, lib1.jar, lib2.jar pr any other jar/directory in your classpath?
Try this to check if the file is being loaded correctly.
On this line:
log4j.rootLogger=info, stdout
chage to
log4j.rootLogger=error, stdout
This will set the log level for the root logger and hence all loggers to ERROR, if you are still seeing the INFO log entries then your log4j.properties file must not be loading correctly, most likely for the reasons stated above.
Can you try this syntax instead?
log4j.category.org.hibernate=ERROR