Pallet uses clojure.tools.logging for its logging. This supports multiple logging implementations. Pallet is most often run using logback as the logging implementation, via the slf4j API support in tools.logging. It is also known to work with log4j.

Logback

Logback is configured using a logback.xml file on the classpath. By default, it will log to standard out.

Dependencies

Slf4j

To enable use of logback, a slf4j dependency needs to be added to your project.

If you are using lein or cake, then add the following to :dependencies in your project.clj file.

[org.slf4j/slf4j-api "1.6.4"]

If you are using maven, then add the following to the <dependencies> section of your pom.xml.

      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
      </dependency>

Logback

To use logback with slf4j, add the following to project.clj.

[ch.qos.logback/logback-classic "1.0.1"]

For maven users:

      <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.0.1</version>
      </dependency>

Example configuration

An example logback.xml configuration file, that can be placed in your project's src or resources directory:

<configuration scan="true" scanPeriod="1 seconds" debug="false">
  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="COMPUTEFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/jclouds-compute.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>logs/old/jclouds-compute.%d{yyyy-MM-dd}.log</fileNamePattern>
      <maxHistory>3</maxHistory>
    </rollingPolicy>
    <encoder>
      <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="WIREFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/jclouds-wire.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>logs/old/jclouds-wire.%d{yyyy-MM-dd}.log</fileNamePattern>
      <maxHistory>3</maxHistory>
    </rollingPolicy>
    <encoder>
      <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="PALLETFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/pallet.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>logs/old/pallet.%d{yyyy-MM-dd}.log</fileNamePattern>
      <maxHistory>3</maxHistory>
    </rollingPolicy>
    <encoder>
      <pattern>%date %level [%thread] %logger{10} %msg%n</pattern>
    </encoder>
  </appender>

  <logger name="jclouds.headers" level="WARN">
    <appender-ref ref="WIREFILE" />
  </logger>

  <logger name="jclouds.wire" level="WARN">
    <appender-ref ref="WIREFILE" />
  </logger>

  <logger name="jclouds.compute" level="WARN">
    <appender-ref ref="COMPUTEFILE" />
  </logger>

  <logger name="jclouds.ssh" level="WARN">
    <appender-ref ref="COMPUTEFILE" />
  </logger>

  <logger name="pallet" level="DEBUG">
    <appender-ref ref="PALLETFILE" />
  </logger>

  <root level="INFO">
    <appender-ref ref="CONSOLE" />
  </root>

</configuration>

Log4j

log4j is configured using a log4j.xml or log4j.properties file on the classpath (the xml file has more functionality than the properties file).

Dependencies

Log4j

The log4j dependency needs to be added to your project.

If you are using lein or cake, then add the following to :dependencies in your project.clj file.

[log4j/log4j "1.2.14"]

If you are using maven, then add the following to the <dependencies> section of your pom.xml.

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
    <optional>true</optional>
</dependency>

Log4j under Slf4j

To use log4j under slf4j, you will need the following in your project.clj:

[org.slf4j/slf4j-api "1.6.4"]
[org.slf4j/slf4f-log4j12 "1.6.4"]

Example configuration

An example log4j.xml configuration file, that can be placed in your project's src or resources directory.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="console" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out"/>
    <param name="Threshold" value="INFO" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
    </layout>
  </appender>

  <appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="logs/jclouds-compute.log" />
    <param name="Append" value="true" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <param name="Threshold" value="TRACE" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
    </layout>
  </appender>

  <appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="logs/jclouds-wire.log" />
    <param name="Append" value="true" />

    <!-- Rollover at midnight each day -->
    <param name="DatePattern" value="'.'yyyy-MM-dd" />

    <param name="Threshold" value="TRACE" />

    <layout class="org.apache.log4j.PatternLayout">
      <!-- The default pattern: Date Priority [Category] Message\n -->
      <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />

      <!--
          The full pattern: Date MS Priority [Category]
          (Thread:NDC) Message\n <param name="ConversionPattern"
          value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
      -->
    </layout>
  </appender>

  <appender name="PALLETFILE" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="logs/pallet.log" />
    <param name="Append" value="true" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <param name="Threshold" value="TRACE" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
    </layout>
  </appender>

  <appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
    <appender-ref ref="COMPUTEFILE" />
  </appender>

  <appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
    <appender-ref ref="WIREFILE" />
  </appender>

  <category name="jclouds.headers">
    <priority value="WARN" />
    <appender-ref ref="ASYNCWIRE" />
  </category>

  <category name="jclouds.wire">
    <priority value="WARN" />
    <appender-ref ref="ASYNCWIRE" />
  </category>

  <category name="jclouds.compute">
    <priority value="INFO" />
    <appender-ref ref="ASYNCCOMPUTE" />
    <appender-ref ref="console" />
  </category>

  <category name="pallet">
    <priority value="INFO" />
    <appender-ref ref="PALLETFILE" />
  </category>

  <category name="jclouds.ssh">
    <priority value="WARN" />
    <appender-ref ref="ASYNCCOMPUTE" />
  </category>

  <root>
    <priority value ="info" />
    <appender-ref ref="console" />
  </root>

</log4j:configuration>