Skip to content

Commit 0438811

Browse files
author
daniel-bryla
committed
iluwatar#502 Replaced usages of System.out with logger.
1 parent 4ca205c commit 0438811

File tree

154 files changed

+1155
-792
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+1155
-792
lines changed

abstract-document/src/main/java/com/iluwatar/abstractdocument/App.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.iluwatar.abstractdocument.domain.HasParts;
2828
import com.iluwatar.abstractdocument.domain.HasPrice;
2929
import com.iluwatar.abstractdocument.domain.HasType;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3032

3133
import java.util.Arrays;
3234
import java.util.HashMap;
@@ -44,11 +46,13 @@
4446
*/
4547
public class App {
4648

49+
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
50+
4751
/**
4852
* Executes the App
4953
*/
5054
public App() {
51-
System.out.println("Constructing parts and car");
55+
LOGGER.info("Constructing parts and car");
5256

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

6973
Car car = new Car(carProperties);
7074

71-
System.out.println("Here is our car:");
72-
System.out.println("-> model: " + car.getModel().get());
73-
System.out.println("-> price: " + car.getPrice().get());
74-
System.out.println("-> parts: ");
75-
car.getParts().forEach(p -> System.out
76-
.println("\t" + p.getType().get() + "/" + p.getModel().get() + "/" + p.getPrice().get()));
75+
LOGGER.info("Here is our car:");
76+
LOGGER.info("-> model: {}", car.getModel().get());
77+
LOGGER.info("-> price: {}", car.getPrice().get());
78+
LOGGER.info("-> parts: ");
79+
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}", p.getType().get(), p.getModel().get(), p.getPrice().get()));
7780
}
7881

7982
/**

abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
package com.iluwatar.abstractfactory;
2424

25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2528
/**
2629
*
2730
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme
@@ -39,6 +42,8 @@
3942
*/
4043
public class App {
4144

45+
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
46+
4247
private King king;
4348
private Castle castle;
4449
private Army army;
@@ -98,17 +103,17 @@ public static void main(String[] args) {
98103

99104
App app = new App();
100105

101-
System.out.println("Elf Kingdom");
106+
LOGGER.info("Elf Kingdom");
102107
app.createKingdom(new ElfKingdomFactory());
103-
System.out.println(app.getArmy().getDescription());
104-
System.out.println(app.getCastle().getDescription());
105-
System.out.println(app.getKing().getDescription());
108+
LOGGER.info(app.getArmy().getDescription());
109+
LOGGER.info(app.getCastle().getDescription());
110+
LOGGER.info(app.getKing().getDescription());
106111

107-
System.out.println("\nOrc Kingdom");
112+
LOGGER.info("Orc Kingdom");
108113
app.createKingdom(new OrcKingdomFactory());
109-
System.out.println(app.getArmy().getDescription());
110-
System.out.println(app.getCastle().getDescription());
111-
System.out.println(app.getKing().getDescription());
114+
LOGGER.info(app.getArmy().getDescription());
115+
LOGGER.info(app.getCastle().getDescription());
116+
LOGGER.info(app.getKing().getDescription());
112117

113118
}
114119

adapter/src/main/java/com/iluwatar/adapter/BattleFishingBoat.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
package com.iluwatar.adapter;
2424

25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2528
/**
2629
*
2730
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip}
@@ -33,6 +36,8 @@
3336
*/
3437
public class BattleFishingBoat implements BattleShip {
3538

39+
private static final Logger LOGGER = LoggerFactory.getLogger(BattleFishingBoat.class);
40+
3641
private FishingBoat boat;
3742

3843
public BattleFishingBoat() {
@@ -41,7 +46,7 @@ public BattleFishingBoat() {
4146

4247
@Override
4348
public void fire() {
44-
System.out.println("fire!");
49+
LOGGER.info("fire!");
4550
}
4651

4752
@Override

adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@
2222
*/
2323
package com.iluwatar.adapter;
2424

25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2528
/**
2629
*
2730
* Device class (adaptee in the pattern). We want to reuse this class
2831
*
2932
*/
3033
public class FishingBoat {
3134

35+
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);
36+
3237
public void sail() {
33-
System.out.println("The Boat is moving to that place");
38+
LOGGER.info("The Boat is moving to that place");
3439
}
3540

3641
public void fish() {
37-
System.out.println("fishing ...");
42+
LOGGER.info("fishing ...");
3843
}
3944

4045
}

aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInformationClientImpl.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.apache.http.impl.client.CloseableHttpClient;
2828
import org.apache.http.impl.client.HttpClients;
2929
import org.apache.http.util.EntityUtils;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3032
import org.springframework.stereotype.Component;
3133

3234
import java.io.IOException;
@@ -37,6 +39,8 @@
3739
@Component
3840
public class ProductInformationClientImpl implements ProductInformationClient {
3941

42+
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInformationClientImpl.class);
43+
4044
@Override
4145
public String getProductTitle() {
4246
String response = null;
@@ -46,7 +50,7 @@ public String getProductTitle() {
4650
response = EntityUtils.toString(httpResponse.getEntity());
4751
}
4852
} catch (IOException e) {
49-
e.printStackTrace();
53+
LOGGER.error("Exception caught.", e);
5054
}
5155
return response;
5256
}

aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInventoryClientImpl.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.apache.http.impl.client.CloseableHttpClient;
2828
import org.apache.http.impl.client.HttpClients;
2929
import org.apache.http.util.EntityUtils;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3032
import org.springframework.stereotype.Component;
3133

3234
import java.io.IOException;
@@ -37,6 +39,8 @@
3739
@Component
3840
public class ProductInventoryClientImpl implements ProductInventoryClient {
3941

42+
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);
43+
4044
@Override
4145
public int getProductInventories() {
4246
String response = "0";
@@ -46,7 +50,7 @@ public int getProductInventories() {
4650
response = EntityUtils.toString(httpResponse.getEntity());
4751
}
4852
} catch (IOException e) {
49-
e.printStackTrace();
53+
LOGGER.error("Exception caught.", e);
5054
}
5155
return Integer.parseInt(response);
5256
}

async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
package com.iluwatar.async.method.invocation;
2424

25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2528
import java.util.concurrent.Callable;
2629

2730
/**
@@ -54,6 +57,8 @@
5457
*/
5558
public class App {
5659

60+
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
61+
5762
/**
5863
* Program entry point
5964
*/
@@ -120,6 +125,6 @@ private static <T> AsyncCallback<T> callback(String name) {
120125
}
121126

122127
private static void log(String msg) {
123-
System.out.println(String.format("[%1$-10s] - %2$s", Thread.currentThread().getName(), msg));
128+
LOGGER.info(msg);
124129
}
125130
}

bridge/src/main/java/com/iluwatar/bridge/Excalibur.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,35 @@
2222
*/
2323
package com.iluwatar.bridge;
2424

25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2528
/**
2629
*
2730
* Excalibur
2831
*
2932
*/
3033
public class Excalibur extends BlindingMagicWeaponImpl {
3134

35+
private static final Logger LOGGER = LoggerFactory.getLogger(Excalibur.class);
36+
3237
@Override
3338
public void wieldImp() {
34-
System.out.println("wielding Excalibur");
39+
LOGGER.info("wielding Excalibur");
3540
}
3641

3742
@Override
3843
public void swingImp() {
39-
System.out.println("swinging Excalibur");
44+
LOGGER.info("swinging Excalibur");
4045
}
4146

4247
@Override
4348
public void unwieldImp() {
44-
System.out.println("unwielding Excalibur");
49+
LOGGER.info("unwielding Excalibur");
4550
}
4651

4752
@Override
4853
public void blindImp() {
49-
System.out.println("bright light streams from Excalibur blinding the enemy");
54+
LOGGER.info("bright light streams from Excalibur blinding the enemy");
5055
}
5156
}

bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,35 @@
2222
*/
2323
package com.iluwatar.bridge;
2424

25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2528
/**
2629
*
2730
* Mjollnir
2831
*
2932
*/
3033
public class Mjollnir extends FlyingMagicWeaponImpl {
3134

35+
private static final Logger LOGGER = LoggerFactory.getLogger(Mjollnir.class);
36+
3237
@Override
3338
public void wieldImp() {
34-
System.out.println("wielding Mjollnir");
39+
LOGGER.info("wielding Mjollnir");
3540
}
3641

3742
@Override
3843
public void swingImp() {
39-
System.out.println("swinging Mjollnir");
44+
LOGGER.info("swinging Mjollnir");
4045
}
4146

4247
@Override
4348
public void unwieldImp() {
44-
System.out.println("unwielding Mjollnir");
49+
LOGGER.info("unwielding Mjollnir");
4550
}
4651

4752
@Override
4853
public void flyImp() {
49-
System.out.println("Mjollnir hits the enemy in the air and returns back to the owner's hand");
54+
LOGGER.info("Mjollnir hits the enemy in the air and returns back to the owner's hand");
5055
}
5156
}

bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,35 @@
2222
*/
2323
package com.iluwatar.bridge;
2424

25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2528
/**
2629
*
2730
* Stormbringer
2831
*
2932
*/
3033
public class Stormbringer extends SoulEatingMagicWeaponImpl {
3134

35+
private static final Logger LOGGER = LoggerFactory.getLogger(Stormbringer.class);
36+
3237
@Override
3338
public void wieldImp() {
34-
System.out.println("wielding Stormbringer");
39+
LOGGER.info("wielding Stormbringer");
3540
}
3641

3742
@Override
3843
public void swingImp() {
39-
System.out.println("swinging Stormbringer");
44+
LOGGER.info("swinging Stormbringer");
4045
}
4146

4247
@Override
4348
public void unwieldImp() {
44-
System.out.println("unwielding Stormbringer");
49+
LOGGER.info("unwielding Stormbringer");
4550
}
4651

4752
@Override
4853
public void eatSoulImp() {
49-
System.out.println("Stormbringer devours the enemy's soul");
54+
LOGGER.info("Stormbringer devours the enemy's soul");
5055
}
5156
}

builder/src/main/java/com/iluwatar/builder/App.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
package com.iluwatar.builder;
2424

2525
import com.iluwatar.builder.Hero.Builder;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
2628

2729
/**
2830
*
@@ -50,6 +52,8 @@
5052
*/
5153
public class App {
5254

55+
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
56+
5357
/**
5458
* Program entry point
5559
*
@@ -60,18 +64,18 @@ public static void main(String[] args) {
6064
Hero mage =
6165
new Hero.Builder(Profession.MAGE, "Riobard").withHairColor(HairColor.BLACK)
6266
.withWeapon(Weapon.DAGGER).build();
63-
System.out.println(mage);
67+
LOGGER.info(mage.toString());
6468

6569
Hero warrior =
6670
new Hero.Builder(Profession.WARRIOR, "Amberjill").withHairColor(HairColor.BLOND)
6771
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL).withWeapon(Weapon.SWORD)
6872
.build();
69-
System.out.println(warrior);
73+
LOGGER.info(warrior.toString());
7074

7175
Hero thief =
7276
new Hero.Builder(Profession.THIEF, "Desmond").withHairType(HairType.BALD)
7377
.withWeapon(Weapon.BOW).build();
74-
System.out.println(thief);
78+
LOGGER.info(thief.toString());
7579

7680
}
7781
}

0 commit comments

Comments
 (0)