LDSTechForumProjects

Logging

For Java Stack 3, we recommend that teams use the the standard Java logging utility (java.util.logging.Logger). It works right out of the box and can be customized very easily. For Java Stack 3 web applications, you can customize your logging configuration using "deploy/src/main/resources/logging.properties". For the QA test runner, you can customize your logging configuration using "qa/src/main/resources/conf/logging.properties". If either of these files does not exist you can copy one from a Java Stack Starter project or simply create and configure it yourself.

Dependencies

Various dependencies in your project may log to different logging APIs, but you can use SLF4J to route all logging messages to the standard Java logging utility by adding the following dependencies to your pom:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
    </dependency>
    <dependency>
        <groupId>org.lds.stack</groupId>
        <artifactId>stack-utils</artifactId>
    </dependency>

Usage

With those dependencies you will only need to learn the standard Java logging API. In addition, the Java Stack provides a LogUtils class that can be used to further simplify logging.

For example:

package org.lds.yourapp;

// The Java logging class
import java.util.logging.Logger;

// Stack utility to simplify working with Loggers
import static org.lds.stack.logging.LogUtils.*;

public class YourClass {
    private static final Logger LOG = getLogger(); // obtains a logger named "org.lds.yourapp.YourClass"

    public void logStuff() {
        severe(LOG, "a critical error message");
        warning(LOG, "a warning message");
        info(LOG, "Something informative");
        fine(LOG, "Fine detail message (for somewhat verbose logging)");
        finer(LOG, "Even finer detail message (for more verbose logging)");
        finest(LOG, "Very fine detail message (for very verbose logging)");
        // Each of the above statements can also take an exception and one or more message arguments
        // See the Logger and LogUtils APIs for details
    }
}
This page was last modified on 29 April 2014, at 05:04.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.