Asyncfilehandler Is Trying to Create Directory Again
Configuring Tomcat logging for a read-only file organisation in Kubernetes.
From this commodity, I volition discuss about how to configure Tomcat server logging for a read-only file system in a container.
Recently I got the chance to work with Kubernetes deployment which will deploy a Tomcat web server, while deploying this awarding I faced an issue that is related to Tomcat server logging….Permit me describe the result to you. Before deploying the application I configured the container which volition run the Tomcat web server equally a read-only file system. At present, this configuration leads me to an error, which was Tomcat internally publishing its own logs to the /logs directory. Since the file organisation was configured as a read-only 1, Tomcat was not able to publish the logs to the /logs directory, because of that my Tomcat deployment was failed. Luckily I found an answer to this problem.
From this article, nosotros are going to talk over the following topics.
1. How Tomcat default loggings are configured.
two. How to redirect tomcat logs to console
3. Configuring the emptyDir volume mount
How Tomcat default loggings are configured.
In default manner tomcat loggings are configured as write to log files in {TOMCAT_HOME}/logs directory and to the console. The following file shows the default tomcat logging configuration defined in {TOMCAT_HOME}/conf/logging.properties file.
handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, coffee.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.
1catalina.org.apache.juli.AsyncFileHandler.maxDays = 90
1catalina.org.apache.juli.AsyncFileHandler.encoding = UTF-8 2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
2localhost.org.apache.juli.AsyncFileHandler.maxDays = ninety
2localhost.org.apache.juli.AsyncFileHandler.encoding = UTF-8 3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
3manager.org.apache.juli.AsyncFileHandler.maxDays = 90
3manager.org.apache.juli.AsyncFileHandler.encoding = UTF-viii 4host-managing director.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base of operations}/logs
4host-director.org.apache.juli.AsyncFileHandler.prefix = host-manager.
4host-manager.org.apache.juli.AsyncFileHandler.maxDays = 90
4host-manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8 java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
java.util.logging.ConsoleHandler.encoding = UTF-eight ############################################################
# Facility specific backdrop.
# Provides actress 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].[/director].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/managing director].handlers = 3manager.org.apache.juli.AsyncFileHandler org.apache.catalina.cadre.ContainerBase.[Catalina].[localhost].[/host-director].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-director.org.apache.juli.AsyncFileHandler # For example, ready the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing country:
#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 letters for HTTP/2 handling, uncomment the following line:
#org.apache.coyote.http2.level = FINE # To see debug messages for WebSocket treatment, uncomment the following line:
#org.apache.tomcat.websocket.level = FINE
Tomcat is publishing logs to four major components, which are Catalina, localhost, manager, and host-manager. As you lot tin run across tomcat uses the org.apache.juli.AsyncFileHandler to write each component log to a file. This juli is implemented as apache's own implementation of several fundamental elements of coffee.util.logging API. This will enable backdrop files to support extended constructs which allow more freedom for defining handlers and assigning them to loggers. A handler'due south log level threshold is INFO by default and can be set using SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, or ALL. You can likewise target specific packages to collect logging from and specify a level.
And then..What could be the issue here?
So far everything is perfect and nice, only when it comes to containerized environments at that place could be some problems. As I mentioned before I was working with a Kubernetes deployment recently, In this deployment I was simply tried to deploy the docker container which will run the tomcat server, but the file system of this container is prepare equally a read-only file system. Once I started my deployment information technology started to get failed, when I checked the logs of my failed container I saw that tomcat was unable to publish its logs to a file in the /logs directory. So we tin can understand that tomcat was not able to write into this file because of the read-simply file system configuration. Tomcat faced this effect because its logs are defined every bit write to a file, And so the solution is nosotros have the set these logs to redirect to the panel.
How to redirect tomcat logs to console
In the default configuration file simply removing the file handlers will stop publishing the logs to a file. Simply in that location should be a proper way to redirect the logs to the console. To do this I was able to come up upward with a new logging configuration.
handlers = 1catalina.java.util.logging.ConsoleHandler, \
2localhost.java.util.logging.ConsoleHandler, \
3manager.java.util.logging.ConsoleHandler, \
4host-manager.java.util.logging.ConsoleHandler .handlers = 1catalina.java.util.logging.ConsoleHandler ############################################################
# console Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################ 1catalina.coffee.util.logging.ConsoleHandler.level = INFO
1catalina.java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
1catalina.java.util.logging.SimpleFormatter.format=[%ane$tc] [:Catalina:] %4$southward %3$s %5$southward %n
1catalina.java.util.logging.ConsoleHandler.encoding = UTF-viii 2localhost.java.util.logging.ConsoleHandler.level = INFO
2localhost.java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
2localhost.java.util.logging.SimpleFormatter.format=[%1$tc] [:localhost:] %4$due south %3$s %v$s %north
2localhost.java.util.logging.ConsoleHandler.encoding = UTF-viii 3manager.java.util.logging.ConsoleHandler.level = INFO
3manager.java.util.logging.ConsoleHandler.formatter = coffee.util.logging.SimpleFormatter
3manager.coffee.util.logging.SimpleFormatter.format=[%1$tc] [:managing director:] %four$s %3$s %5$southward %n
3manager.java.util.logging.ConsoleHandler.encoding = UTF-eight 4host-manager.java.util.logging.ConsoleHandler.level = INFO
4host-manager.java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
4host-manager.coffee.util.logging.SimpleFormatter.format= [%1$tc] [:host-manager:] %iv$southward %iii$s %5$s %n
4host-director.java.util.logging.ConsoleHandler.encoding = UTF-eight ############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################ org.apache.catalina.cadre.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.coffee.util.logging.ConsoleHandler org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/director].level = INFO
org.apache.catalina.cadre.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.coffee.util.logging.ConsoleHandler org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.coffee.util.logging.ConsoleHandler # 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 encounter debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE # To come across debug letters for HTTP/2 treatment, uncomment the following line:
#org.apache.coyote.http2.level = FINE # To see debug messages for WebSocket treatment, uncomment the following line:
#org.apache.tomcat.websocket.level = FINE
Yous can see that I have introduced new console handlers to redirect tomcat logs to the console using coffee.util.logging.ConsoleHandler.
- <handler-name>.level specifies the default level for the
Handler(defaults toLevel.INFO). - <handler-proper name>.filter specifies the proper name of a
Filterclass to employ (defaults to noFilter). - <handler-name>.formatter specifies the proper name of a
Formattercourse to apply (defaults tocoffee.util.logging.SimpleFormatter). - <handler-name>.encoding the proper noun of the grapheme prepare encoding to use (defaults to the default platform encoding).
But the problem is still in that location, With this configuration, I was not able to redirect the tomcat admission logs to the panel. Because of that, my deployment started to fail once again due to the read-merely file system configuration in my deployment. Currently, you can not redirect the tomcat access logs to the console considering access logs configurations are defined in the server.xml file in guild to provide a new configuration for access logs you have to come up with a new custom valve implementation. So what I did to resolve this issue was mounting an emptyDir volume mount to the /logs directory in tomcat.
Configuring the emptyDir volume mount
To resolve this issue I tried to mount an emptyDir book to the default logging directory in tomcat which is "/logs" directory. emptyDir volume is initially empty, so when you mounting it delight make sure that y'all don't accept any files in that directory because when you mount an emptyDir it will initially create an empty directory in the corresponding location, which may remove your other files in that directory also. the best matter nearly emptyDir is that all containers in a pod tin read and write the same files in the emptyDir. So this volition resolve our issue by letting the tomcat write the logs to the emptyDir volume mountain which is mounted to the "/logs" directory.
volumes:
emptyDir: {}
- name: tomcat-logs-dir One time you define the emptyDir you accept to mount it to the tomcat "/logs" directory.
volumeMounts:
- name: tomcat-logs-dir
mountPath: /usr/local/tomcat/logs Once I did this change I was able to lunch my tomcat server with a read-only file organization configuration for my deployment. You can log into the container and check the logs and y'all should be able to see the logs in the console except for access logs, to check the access logs you lot can go to the /logs directory cheque the access log file there. Then I hope this commodity volition aid you configuring the apache logs in your deployment :).
Source: https://medium.com/codex/configuring-tomcat-logging-for-a-read-only-file-system-in-kubernetes-965556e55045
0 Response to "Asyncfilehandler Is Trying to Create Directory Again"
Post a Comment