Permalink
Browse files

Adds basic console logging to demonstrate slf4j library usage.

  • Loading branch information...
CodeCramp committed Mar 19, 2018
1 parent 01191a0 commit 85045c33edd75bbe2628041428e91906cbcfee1b
@@ -24,6 +24,8 @@ targetCompatibility = 1.8
// Actual dependencies to be pulled.
dependencies {
compile 'org.springframework:spring-context:5.0.0.RELEASE'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
}


@@ -1,5 +1,7 @@
package com.codecramp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -12,20 +14,26 @@
@Configuration
@ComponentScan
public class Application {

private static final Logger LOG = LoggerFactory.getLogger(Application.class);

public static void main(String[] args) {
LOG.info("Setting up application context");
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(Application.class);
LOG.info("Instantiating greeting instances");
Greeting helloGreeting = context.getBean(HelloGradle.class);
Greeting byeGreeting = context.getBean(ByeGradle.class);
Greeting customGreeting = context.getBean(CustomGreeting.class);

LOG.info("Invoking greetings");
System.out.println("\n\n");
helloGreeting.greet();
byeGreeting.greet();
customGreeting.greet();
System.out.println("\n\n");

LOG.info("Closing the Spring Context");
context.close();
}
}
@@ -1,12 +1,16 @@
package com.codecramp.greeting;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class ByeGradle implements Greeting {
private static final Logger LOG = LoggerFactory.getLogger(ByeGradle.class);

@Override
public void greet() {
LOG.debug("Executing Bye greeting");
System.out.println("Bye Gradle!!!");
}
}
@@ -1,11 +1,15 @@
package com.codecramp.greeting;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class CustomGreeting implements Greeting {
private static final Logger LOG = LoggerFactory.getLogger(CustomGreeting.class);

private String greeting;
private String greeter;

@@ -19,6 +23,7 @@ public CustomGreeting(@Value("Hey There!!!") final String greeting, @Value("Code

@Override
public void greet() {
LOG.debug("Executing custom greeting");
System.out.println(greeting + ", I am - " + greeter);
}
}
@@ -1,12 +1,16 @@
package com.codecramp.greeting;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class HelloGradle implements Greeting {
private static final Logger LOG = LoggerFactory.getLogger(HelloGradle.class);

@Override
public void greet() {
LOG.debug("Executing Hello greeting");
System.out.println("Hello Gradle!!!");
}
}

0 comments on commit 85045c3

Please sign in to comment.