Skip to content

Logging

Adrian Pena edited this page Sep 26, 2016 · 1 revision

jBlinky delegates the logging implementation to your application through the SLF4J Logging facade.

In order for jBlinky to spit logs, you first need to have a Logging framework already implemented and configured in your application. SLF4J supports a bunch of Logging frameworks and integrating your Logging framework to SLF4J is usually a matter of adding a dependency to the project.

NOTE: If you are not very familiar with SLF4J or Logging frameworks, I recommend you reading the SLF4J Documentation. If you are in the business of choosing a Logging framework, it is always a very subjective and usually not-so-fun thing, people have their arguments, pros and cons, probably google can help you start.

Simple Logging

If you don't require a robust logging infrastructure and don't want to bother too much with Logging configurations you could integrate the SLF4J Simple Logging framework.

Just add the SLF4J Simple dependency to your project:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>ADD_LATEST_VERSION_HERE</version> 
</dependency>

And that's pretty much it, upon execution, it will start printing the jBlinky logs on console in a beautiful red color (if your console supports colors) and the minimum logging level will be INFO.

If you want to get DEBUG level logs, you can set a properties file with the org.slf4j.simpleLogger.defaultLogLevel property defined in it, or you can just execute your application with this parameter:

-Dorg.slf4j.simpleLogger.defaultLogLevel=debug

Here's the SLF4J Simple Logger documentation if you need more details.

LogBack, Log4J, Log4J2

I am not going to go in super detail on how to setup LogBack, Log4J or Log4J2, the interwebs already has plenty of tutorials and discussions on such matter. The only important thing to know is that for some of them you require the connector between SLF4J and your Logger.

For example, if you are using Log4J you need this dependency:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
    <version>ADD_LATEST_VERSION_HERE</version>
</dependency>

Using Spring Boot?

If you are using Spring Boot, you only require the spring-boot-starter-logging library but chances are, it is most probably already a transitive dependency upon your project's Spring Boot dependencies (if you have spring-boot-starter or spring-boot-starter-web as dependencies, you have it furrr sure).

But if for some reason you don't have it, just add it:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-logging</artifactId>
</dependency>

NOTE: I didn't added the version in there, I am assuming that your project is maven configured and the parent is spring-boot-starter-parent, if that's not the case, just add the version you are using for all your other spring boot stuff.

Clone this wiki locally