Quick SLF4J logging with Intellij / Idea

**Sometimes you just want things to work.  Here is a _quick_ logging solution I got working with Intellij.**
  1.  I created a new Java project in Idea (Intellij).   I created a lib directory (in the Intellij) project.

  2.  I downloaded slf4j from http://www.slf4j.org/download.html

  3.  Unzip, and copy slf4j-1.7.5/slf4j-api-1.7.5.jar slf4j-1.7.5/slf4j-simple-1.7.5.jar to the Idea lib directory.

  4.  Intellij.  Right click on both jars, and select “Add to Library…”

  5.  Copy the following to src/log4j.properties (this will be picked up by the classpath):

log4j.rootLogger=DEBUG, STDOUT log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

  1.  Copy the following Java code (you will see the following output, when you run it):

[main] INFO com.chocksaway.SayHello - hello

Process finished with exit code 0

The logger is working OK.

package com.chocksaway;

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

public class SayHello { private final Logger logger = LoggerFactory.getLogger(SayHello.class);

private void sayHello() { logger.info(“hello”); }

public static void main(String args[]) { SayHello scanner = new SayHello(); scanner.sayHello(); }


Author | Miles Davenport

Career programmer, who designs, assembles, fixes, and supports customers, software and systems.