Logging – Java web applications on Azure Websites.

Default Apache Tomcat Installation

Logging for the default installation of Apache Tomcat 7.0.50 on Microsoft Azure Websites is configured so that logs are written to d:\home\LogFiles directory.

You should see the following files in your d:\home\LogFiles directory by default:

  1. httpPlatformStdout – Check for errors during java process launch or startup.
  2. catalina.yyyy-mm-dd.log – Tomcat logs.
  3. site.yyyy-mm-dd.log – web application logs.
  4. site_access_log.yyyy-mm-dd.txt – access logs.

Note: host-manager*log and manager.*.log will always be empty as the tomcat manager application is disabled.

Any customization of logging can be done via

  1. <application>\WEB-INF\classes\logging.properties -

    Configure default java.Util.Logging as described in http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_java.util.logging_(default).

    For example, in your <application>\WEB-INF\classes\logging.properties

    handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
    ############################################################
    # Handler specific properties.
    # Describes specific configuration info for Handlers.
    ############################################################
    org.apache.juli.FileHandler.level = ALL
    org.apache.juli.FileHandler.directory = d:/home/LogFiles
    org.apache.juli.FileHandler.prefix = example.
    java.util.logging.ConsoleHandler.level = ALL
    java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

  2. <application>\META-INF\context.xml – Configure access logs for your web application as described in http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Log_Valve.

    For example, if you have a web application “helloworld”, and you want to customize access logs for this application, you will need META-INF\context.xml file under your application directory with the following contents:

    <Context docBase="helloworld" path="" reloadable="true">
      <Valve className="org.apache.catalina.valves.AccessLogValve"
             directory="d:/home/LogFiles"
             prefix="site_access_log."
             suffix=".txt"
             pattern="%h %l %u %t &quot;%r&quot; %s %b %D" />
    </Context>

Default Jetty Installation

Logging for the default installation of Jetty 9.1.0.v20131115 on Microsoft Azure Websites is configured so that logs are written to d:\home\LogFiles directory.

You should see the following files in your d:\home\LogFiles directory by default:

  1. httpPlatformStdout – Check for errors during java process launch or startup.
  2. jetty_yyyy_mm_dd.stderrout.log – Jetty logs.

Customizing Jetty Logging requires you to have your own jetty-logging.xml file in your site and then modifying web.config to point Jetty to use your jetty-logging.xml file. An example jetty-logging.xml file is shown below which sets the log level to DEBUG :

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="Server">
  <New id="ServerLog">
    <Arg>
      <New>
        <Arg>
          <Property name="jetty.logs" default="d:\home\LogFiles"/>/<Property name="jetty.logfile" default="jetty_custom_yyyy_mm_dd.stderrout.log"/>
        </Arg>
        <Arg type="boolean">false</Arg>
        <Arg type="int">90</Arg>
        <Arg><Call name="getTimeZone"><Arg>GMT</Arg></Call></Arg>
        <Get id="ServerLogName" name="datedFilename"/>
      </New>
    </Arg>
  </New>
  <Get name="rootLogger">
    <Call name="info">
      <Arg>Redirecting stderr/stdout to <Ref refid="ServerLogName"/></Arg>
    </Call>
    <Call name="setDebugEnabled"> <Arg type="boolean">true</Arg> </Call>
  </Get>
  <Call name="setErr"><Arg><Ref refid="ServerLog"/></Arg></Call>
  <Call name="setOut"><Arg><Ref refid="ServerLog"/></Arg></Call>
</Configure>

The web.config file to use your custom jetty-logging.xml file is shown below assuming you place your jetty-logging.xml in d:\home\site\wwwroot\jetty-logging.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httppPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform
      processPath="%JAVA_HOME%\bin\java.exe"
      arguments="-Djava.net.preferIPv4Stack=true
        -Djetty.port=%HTTP_PLATFORM_PORT%
        -Djetty.base=&quot;%programfiles(x86)%\jetty-distribution-9.1.0.v20131115&quot;
        -Djetty.webapps=&quot;d:\home\site\wwwroot\webapps&quot;
        -jar &quot;%programfiles(x86)%\jetty-distribution-9.1.0.v20131115\start.jar&quot;
        d:\home\site\wwwroot\jetty-logging.xml">
    </httpPlatform>
  </system.webServer>
</configuration>

For more information on jetty logging, please click here.

Another example shown below is to Configure Jetty request logs for your application:

There are 2 ways you can configure request logs for your jetty web application.

  1. Use custom jetty-requestlog.xml (you could copy the one from jetty-distribution\etc\jetty-requestlog.xml). Place this xml file in d:\home\site\wwwroot\jetty-requestlog.xml and configure web.config to point to this xml file.

    Example jetty-requestlog.xml

    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
    <!-- =============================================================== -->
    <!-- Configure the Jetty Request Log -->
    <!-- =============================================================== -->
    <Configure id="Server">
    <!-- =========================================================== -->
    <!-- Configure Request Log -->
    <!-- =========================================================== -->
      <Ref refid="Handlers">
        <Call name="addHandler">
          <Arg>
            <New id="RequestLog">
              <Set name="requestLog">
            <New id="RequestLogImpl">
              <Set name="filename">d:/home/LogFiles/request_yyyy_mm_dd.request.log</Set>
              <Set name="filenameDateFormat">yyyy_MM_dd</Set>
              <Set name="retainDays">
                <Property name="requestlog.retain" default="90"/>
              </Set>
              <Set name="append">
                <Property name="requestlog.append" default="true"/>
              </Set>
              <Set name="extended">
                <Property name="requestlog.extended" default="false"/>
              </Set>
              <Set name="logCookies">
                <Property name="requestlog.cookies" default="false"/>
              </Set>
              <Set name="LogTimeZone">
                <Property name="requestlog.timezone" default="GMT"/>
              </Set>
            </New>
          </Set>
          </New>
          </Arg>
        </Call>
      </Ref>
    </Configure>

    Web.config configured to use d:\home\site\wwwroot\jetty-requestlog.xml -

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <handlers>
          <add name="httppPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
        </handlers>
        <httpPlatform
            processPath="%JAVA_HOME%\bin\java.exe"
            arguments="-Djava.net.preferIPv4Stack=true
                -Djetty.port=%HTTP_PLATFORM_PORT%
                -Djetty.base=&quot;%programfiles(x86)%\jetty-distribution-9.1.0.v20131115&quot;
                -Djetty.webapps=&quot;d:\home\site\wwwroot\webapps&quot;
                -jar &quot;%programfiles(x86)%\jetty-distribution-9.1.0.v20131115\start.jar&quot;
                d:\home\site\wwwroot\jetty-logging.xml
                d:\home\site\wwwroot\jetty-requestlog.xml">
        </httpPlatform>
      </system.webServer>
    </configuration>

  2. Configure request log in your applications <context>.xml as described here – https://wiki.eclipse.org/Jetty/Tutorial/RequestLog#Configuring_Separate_Request_Log_For_Web_Application.

    Example – if you have an application helloworld.war, you need helloworld.xml where helloworld.war is located. This xml defines the context for this application and you can configure request logs by having the following contents in helloworld.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Configure PUBLIC
    "-//Mort Bay Consulting//DTD Configure//EN"
    "http://www.eclipse.org/jetty/configure_9_0.dtd">
     
    <Configure>
      <Set name="war">d:/home/site/wwwroot/webapps/helloworld.war</Set>
      <Set name="contextPath">/helloworld</Set>
      <Set name="handler">
        <New id="RequestLog">
          <Set name="requestLog">
            <New id="RequestLogImpl">
              <Set name="filename">d:/home/LogFiles/requests-yyyy_mm_dd.request.log</Set>
              <Set name="filenameDateFormat">yyyy_MM_dd</Set>
              <Set name="LogTimeZone">GMT</Set>
              <Set name="retainDays">90</Set>
              <Set name="append">true</Set>
            </New>
          </Set>
        </New>
      </Set>
    </Configure>

 

Apache Tomcat from App Gallery OR Custom Tomcat

If you have the Apache Tomcat from App Gallery or your own version of Apache Tomcat, you have the full installation of tomcat and you can configure logging as per your needs. Apache Tomcat from App Gallery has been configured to write logs to d:\home\LogFiles directory. For your custom installations, the recommendation is that you write logs to d:\home\LogFiles directory so you will be able to take advantage of Azure Tools to stream logs. Click here to learn more about Tomcat Logging.

 

Jetty from App Gallery OR Custom Jetty

If you have Jetty from App Gallery or your own version of Jetty, you have the full installation of jetty and you can configure logging as per your needs. Jetty from App Gallery has been configured to write logs to d:\home\LogFiles directory. For your custom installations, the recommendation is that you write logs to d:\home\LogFiles directory so you will be able to take advantage of Azure Tools to stream logs. Click here to learn more about Jetty Logging.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>