5

Let me start by saying I am not a Tomee/TomCat expert.

I have an application (.war) running in a Tomee based Docker container on ECS/Fargate on AWS. I am trying to get Tomee to send all logs to STDOUT so that logs from the application will be sent to CloudWatch in AWS. I have tried the suggestions/answers in this question but I am still not seeing application logs even when testing locally:

docker logs -f myapp

Here is the logging.properties file with the added java.util.logging.ConsoleHandler:

handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, org.apache.tomee.jul.formatter.AsyncConsoleHandler
.handlers = 1catalina.org.apache.juli.AsyncFileHandler, org.apache.tomee.jul.formatter.AsyncConsoleHandler, 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 = 90
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-8

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.
4host-manager.org.apache.juli.AsyncFileHandler.maxDays = 90
4host-manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8

org.apache.tomee.jul.formatter.AsyncConsoleHandler.level = FINE
org.apache.tomee.jul.formatter.AsyncConsoleHandler.formatter = org.apache.juli.OneLineFormatter
org.apache.tomee.jul.formatter.AsyncConsoleHandler.encoding = UTF-8


############################################################
# 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, java.util.logging.ConsoleHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler, java.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.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler

I have added an environment variable as suggested in /usr/local/tomee/bin/:

#!/bin/bash
CATALINA_OUT=/dev/stdout

All of the logs sent to STDOUT are automatically sent to AWS Cloudwatch (I can see the information from the Catalina logs there) but the access/error logs are not.

Have I missed something here? Or is there an easier way to make sure the application's logs are seen in CloudWatch?

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119

1 Answers1

3

After much research, I have found that using the following statements in server.xml will send the logs to STDOUT using AccessLogValve:

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/dev/stdout"
   prefix="" suffix="" rotatable="false"
   pattern="%h %l %u %t &quot;%r&quot; %s %b" />

OR

<Valve className="[...].AccessLogValve" directory="/dev"
    prefix="stdout" suffix="" fileDateFormat=""
    pattern="%h %l %u %t &quot;%r&quot; %s %b"
/>

Dependent upon the version of Tomcat/Tomee both of these work well without the need for soft linking the actual logs to /dev/stdout

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119