1

I normally use Log4J. I am trying to understand how JULI is configured in the Tomcat server. I have provided my understanding of what these lines mean starting with the character *. Can you please make sure my understanding is correct please.

 *THE SET OF ALL HANDLERS HAVE TO BE DECLARED AS VALUES OF handlers
handlers = 1catalina.org.apache.juli.FileHandler,2localhost.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

 *THIS IS THE SET OF HANDLERS ALL LOGGERS WILL HAVE THESE HANDLERS like rootLogger IN LOG4J. YOU DO NOT HAVE DECLARE THEM FOR ANY LOGGERS.
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

 *THIS IS THE CONFIGURATION FOR ALL THE HANDLERS
############################################################
# 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.
############################################################
 *[localhost].handlers IS THE SPECIFIC HANDLER FOR LOCALHOST 
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 am confused by this line: .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

Does every logger get these two loggers even if they have declared their own loggers? So when a message is logged to 2localhost.org.apache.juli.FileHandler it also logged to 1catalina.org.apache.juli.FileHandler and java.util.logging.ConsoleHandler.

Or if a logger has its handlers set, logging will not occur on 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler because its handlers are set.

Any help is welcomed.

shodz
  • 344
  • 3
  • 13

1 Answers1

2

The Logging in Tomcat documentation will answer your questions.

I am confused by this line: .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

Does every logger get these two loggers even if they have declared their own loggers? So when a message is logged to 2localhost.org.apache.juli.FileHandler it also logged to 1catalina.org.apache.juli.FileHandler and java.util.logging.ConsoleHandler.

Per the documentation page above:

A prefix may be added to handler names, so that multiple handlers of a single class may be instantiated. A prefix is a String which starts with a digit, and ends with '.'. For example, 22foobar. is a valid prefix.

The standard JUL LogManager doesn't support multiple configurations per a single class name. By adding the prefix it allows JULI to create multiple instances of the same class type with different configurations from the logging.properties.

So going back to your example config file in your question, 1catalina. and 2localhost. are just prefix identifiers to create a org.apache.juli.FileHandler with a specific configuration.

I am interested on the ".handlers" entry in the properties file. Do you know what the "." character does?

For Tomcat, this is explained in: Why we need two times write handlers in tomcat logging.properties?

jmehrens
  • 10,580
  • 1
  • 38
  • 47