Skip to content

Commit

Permalink
iluwatar#502 Replaced usages of System.out with logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-bryla committed Oct 23, 2016
1 parent 4ca205c commit 0438811
Show file tree
Hide file tree
Showing 154 changed files with 1,155 additions and 792 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.iluwatar.abstractdocument.domain.HasParts;
import com.iluwatar.abstractdocument.domain.HasPrice;
import com.iluwatar.abstractdocument.domain.HasType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -44,11 +46,13 @@
*/
public class App {

private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

/**
* Executes the App
*/
public App() {
System.out.println("Constructing parts and car");
LOGGER.info("Constructing parts and car");

Map<String, Object> carProperties = new HashMap<>();
carProperties.put(HasModel.PROPERTY, "300SL");
Expand All @@ -68,12 +72,11 @@ public App() {

Car car = new Car(carProperties);

System.out.println("Here is our car:");
System.out.println("-> model: " + car.getModel().get());
System.out.println("-> price: " + car.getPrice().get());
System.out.println("-> parts: ");
car.getParts().forEach(p -> System.out
.println("\t" + p.getType().get() + "/" + p.getModel().get() + "/" + p.getPrice().get()));
LOGGER.info("Here is our car:");
LOGGER.info("-> model: {}", car.getModel().get());
LOGGER.info("-> price: {}", car.getPrice().get());
LOGGER.info("-> parts: ");
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}", p.getType().get(), p.getModel().get(), p.getPrice().get()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
package com.iluwatar.abstractfactory;

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

/**
*
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme
Expand All @@ -39,6 +42,8 @@
*/
public class App {

private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

private King king;
private Castle castle;
private Army army;
Expand Down Expand Up @@ -98,17 +103,17 @@ public static void main(String[] args) {

App app = new App();

System.out.println("Elf Kingdom");
LOGGER.info("Elf Kingdom");
app.createKingdom(new ElfKingdomFactory());
System.out.println(app.getArmy().getDescription());
System.out.println(app.getCastle().getDescription());
System.out.println(app.getKing().getDescription());
LOGGER.info(app.getArmy().getDescription());
LOGGER.info(app.getCastle().getDescription());
LOGGER.info(app.getKing().getDescription());

System.out.println("\nOrc Kingdom");
LOGGER.info("Orc Kingdom");
app.createKingdom(new OrcKingdomFactory());
System.out.println(app.getArmy().getDescription());
System.out.println(app.getCastle().getDescription());
System.out.println(app.getKing().getDescription());
LOGGER.info(app.getArmy().getDescription());
LOGGER.info(app.getCastle().getDescription());
LOGGER.info(app.getKing().getDescription());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
package com.iluwatar.adapter;

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

/**
*
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip}
Expand All @@ -33,6 +36,8 @@
*/
public class BattleFishingBoat implements BattleShip {

private static final Logger LOGGER = LoggerFactory.getLogger(BattleFishingBoat.class);

private FishingBoat boat;

public BattleFishingBoat() {
Expand All @@ -41,7 +46,7 @@ public BattleFishingBoat() {

@Override
public void fire() {
System.out.println("fire!");
LOGGER.info("fire!");
}

@Override
Expand Down
9 changes: 7 additions & 2 deletions adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@
*/
package com.iluwatar.adapter;

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

/**
*
* Device class (adaptee in the pattern). We want to reuse this class
*
*/
public class FishingBoat {

private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);

public void sail() {
System.out.println("The Boat is moving to that place");
LOGGER.info("The Boat is moving to that place");
}

public void fish() {
System.out.println("fishing ...");
LOGGER.info("fishing ...");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;
Expand All @@ -37,6 +39,8 @@
@Component
public class ProductInformationClientImpl implements ProductInformationClient {

private static final Logger LOGGER = LoggerFactory.getLogger(ProductInformationClientImpl.class);

@Override
public String getProductTitle() {
String response = null;
Expand All @@ -46,7 +50,7 @@ public String getProductTitle() {
response = EntityUtils.toString(httpResponse.getEntity());
}
} catch (IOException e) {
e.printStackTrace();
LOGGER.error("Exception caught.", e);
}
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;
Expand All @@ -37,6 +39,8 @@
@Component
public class ProductInventoryClientImpl implements ProductInventoryClient {

private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);

@Override
public int getProductInventories() {
String response = "0";
Expand All @@ -46,7 +50,7 @@ public int getProductInventories() {
response = EntityUtils.toString(httpResponse.getEntity());
}
} catch (IOException e) {
e.printStackTrace();
LOGGER.error("Exception caught.", e);
}
return Integer.parseInt(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
package com.iluwatar.async.method.invocation;

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

import java.util.concurrent.Callable;

/**
Expand Down Expand Up @@ -54,6 +57,8 @@
*/
public class App {

private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

/**
* Program entry point
*/
Expand Down Expand Up @@ -120,6 +125,6 @@ private static <T> AsyncCallback<T> callback(String name) {
}

private static void log(String msg) {
System.out.println(String.format("[%1$-10s] - %2$s", Thread.currentThread().getName(), msg));
LOGGER.info(msg);
}
}
13 changes: 9 additions & 4 deletions bridge/src/main/java/com/iluwatar/bridge/Excalibur.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,35 @@
*/
package com.iluwatar.bridge;

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

/**
*
* Excalibur
*
*/
public class Excalibur extends BlindingMagicWeaponImpl {

private static final Logger LOGGER = LoggerFactory.getLogger(Excalibur.class);

@Override
public void wieldImp() {
System.out.println("wielding Excalibur");
LOGGER.info("wielding Excalibur");
}

@Override
public void swingImp() {
System.out.println("swinging Excalibur");
LOGGER.info("swinging Excalibur");
}

@Override
public void unwieldImp() {
System.out.println("unwielding Excalibur");
LOGGER.info("unwielding Excalibur");
}

@Override
public void blindImp() {
System.out.println("bright light streams from Excalibur blinding the enemy");
LOGGER.info("bright light streams from Excalibur blinding the enemy");
}
}
13 changes: 9 additions & 4 deletions bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,35 @@
*/
package com.iluwatar.bridge;

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

/**
*
* Mjollnir
*
*/
public class Mjollnir extends FlyingMagicWeaponImpl {

private static final Logger LOGGER = LoggerFactory.getLogger(Mjollnir.class);

@Override
public void wieldImp() {
System.out.println("wielding Mjollnir");
LOGGER.info("wielding Mjollnir");
}

@Override
public void swingImp() {
System.out.println("swinging Mjollnir");
LOGGER.info("swinging Mjollnir");
}

@Override
public void unwieldImp() {
System.out.println("unwielding Mjollnir");
LOGGER.info("unwielding Mjollnir");
}

@Override
public void flyImp() {
System.out.println("Mjollnir hits the enemy in the air and returns back to the owner's hand");
LOGGER.info("Mjollnir hits the enemy in the air and returns back to the owner's hand");
}
}
13 changes: 9 additions & 4 deletions bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,35 @@
*/
package com.iluwatar.bridge;

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

/**
*
* Stormbringer
*
*/
public class Stormbringer extends SoulEatingMagicWeaponImpl {

private static final Logger LOGGER = LoggerFactory.getLogger(Stormbringer.class);

@Override
public void wieldImp() {
System.out.println("wielding Stormbringer");
LOGGER.info("wielding Stormbringer");
}

@Override
public void swingImp() {
System.out.println("swinging Stormbringer");
LOGGER.info("swinging Stormbringer");
}

@Override
public void unwieldImp() {
System.out.println("unwielding Stormbringer");
LOGGER.info("unwielding Stormbringer");
}

@Override
public void eatSoulImp() {
System.out.println("Stormbringer devours the enemy's soul");
LOGGER.info("Stormbringer devours the enemy's soul");
}
}
10 changes: 7 additions & 3 deletions builder/src/main/java/com/iluwatar/builder/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
package com.iluwatar.builder;

import com.iluwatar.builder.Hero.Builder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
Expand Down Expand Up @@ -50,6 +52,8 @@
*/
public class App {

private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

/**
* Program entry point
*
Expand All @@ -60,18 +64,18 @@ public static void main(String[] args) {
Hero mage =
new Hero.Builder(Profession.MAGE, "Riobard").withHairColor(HairColor.BLACK)
.withWeapon(Weapon.DAGGER).build();
System.out.println(mage);
LOGGER.info(mage.toString());

Hero warrior =
new Hero.Builder(Profession.WARRIOR, "Amberjill").withHairColor(HairColor.BLOND)
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL).withWeapon(Weapon.SWORD)
.build();
System.out.println(warrior);
LOGGER.info(warrior.toString());

Hero thief =
new Hero.Builder(Profession.THIEF, "Desmond").withHairType(HairType.BALD)
.withWeapon(Weapon.BOW).build();
System.out.println(thief);
LOGGER.info(thief.toString());

}
}
Loading

0 comments on commit 0438811

Please sign in to comment.