Sam
Sam

Reputation: 31

How to eleminate localhost.log files in tomcat application

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?

Upvotes: 3

Views: 2237

Answers (1)

Paul Wasilewski
Paul Wasilewski

Reputation: 10372

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.

  1. 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.
    
  2. Set the catalina file handler

    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 1catalina.org.apache.juli.FileHandler
    

Upvotes: 1

Related Questions