Skip to content

Logging Configuration

Miere edited this page Jan 7, 2018 · 3 revisions

Logging Configution

Kikaha uses SLF4J as its main log implementation. It means you can use any logging service that is compatible with SLF4J as you logging implementation.

Using the SLF4j

Bellow a sample code using the core API.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// http://www.slf4j.org/manual.html
public class HelloWorld {

  private static final 
    Logger logger = LoggerFactory.getLogger(HelloWorld.class);

  public static void main(String[] args) {
    logger.info("Hello World");
  }
}

If you are a Lombok user, you will have a more clean HelloWorld code.

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HelloWorld {
  public static void main(String[] args) {
    log.info("Hello World");
  }
}

Configuring a log appender

On the first run of your HelloWorld sample you will face the following warning message.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

This is a simple message printed from SLF4j warning you that only its api (slf4j-api) was present in the classpath. If you have followed the Getting Started guide or included the kikaha-project module on your maven project (as parent or at dependencyManagement), just include one of the following on your dependencies.

<!-- Simple Logging -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
</dependency>
<!-- Log4J -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
</dependency>
<!-- Logback -->
<dependency>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
</dependency>

For more logging options or details please consult the SLF4j manual.

Clone this wiki locally