Logging in the Java client library is configured with SLF4J, a generic logging
facade for Java that allows logs to be directed to many different logging
implementations, such as Log4j 2, Logback, or `java.util.logging` (JUL). We
provide sample configuration files for Log4j 2 and JUL.

## Log layout and functionality

Requests are logged with a one-line summary and the full request and response
body and headers.

| Log type | Log name | Success level | Failure level |
|---|---|---|---|
| SUMMARY | com.google.ads.googleads.lib.request.summary | INFO | WARN |
| DETAIL | com.google.ads.googleads.lib.request.detail | DEBUG | INFO |

> [!IMPORTANT]
> **Key Point:** Mutate requests where [partial failure](https://developers.google.com/google-ads/api/samples/handle-partial-failure) is `true` don't cause the entire request to fail. Thus, partial failure logs are always logged at the Success level, not at the Failure level.

## Detail log truncation

The detailed logs are truncated by default to avoid creating large logs. To
change the length at which logs are truncated, set the JVM property
`-Dapi.googleads.maxLogMessageLength=<number>`. Setting `-1` disables log
truncation.

## Log4j 2

1. Add a dependency on the `log4j-slf4j2-impl` library, substituting `2.x.y`
   with the version of Log4j 2 you are using in your project:

       <dependency>
         <groupId>org.apache.logging.log4j</groupId>
         <artifactId>log4j-slf4j2-impl</artifactId>
         <version>2.x.y</version>
       </dependency>

2. (Optional) Create a `log4j2.xml` configuration file in your resources
   directory (for example, `src/main/resources` in Maven). Log4j 2 loads its
   configuration file from the classpath, not the working directory, so ensure
   you create it in a resources directory.

3. Run your application, specifying
   `-Dlog4j.configurationFile=<CONFIG_FILE_PATH>`. You can specify
   `CONFIG_FILE_PATH=googleads-logging/log4j2.xml` to use the default
   configuration file included with the client library.

## Log4j 1.2 (legacy)

1. Add a dependency on the `slf4j-log4j12` library, substituting `1.x.y` with
   the version of Log4j 1.2 you are using in your project:

       <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-log4j12</artifactId>
         <version>1.x.y</version>
       </dependency>

2. (Optional) Create a configuration file in your project's resources
   directory, for example `src/main/resources` in Maven. Log4j 1.2 loads its
   configuration file from the classpath, not the working directory, so ensure
   you copy it to a resources directory.

3. Run your application, specifying `-Dlog4j.configuration=<CONFIG_FILE_PATH>`.
   You can specify `CONFIG_FILE_PATH=googleads-logging/log4j.properties` to use
   the default configuration file included with the client library.

## Java Util Logging

1. Add a dependency on the `slf4j-jdk14` library, substituting `2.x.y` with the
   SLF4J version used in your project:

       <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-jdk14</artifactId>
         <version>2.x.y</version>
       </dependency>

2. Create a JUL configuration file on the file system in a path readable from
   your application (for instance, `./jdk-logger.properties`). A template is
   provided at
   `google-ads/src/main/resources/googleads-logging/jdk-logger.properties`. JUL
   reads from the file system only, so don't copy it only to the classpath
   resources directory.

3. Run your application specifying
   `-Djava.util.logging.config.file=./jdk-logger.properties`.