Skip to content

Commit 68ec24c

Browse files
authored
Merge pull request iluwatar#515 from dbryla/master
iluwatar#502 Added logging framework to repository
2 parents 95b651f + 3091ff2 commit 68ec24c

File tree

215 files changed

+2926
-2449
lines changed

Some content is hidden

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

215 files changed

+2926
-2449
lines changed

.gitignore

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
target
2-
.metadata
3-
.settings
4-
.classpath
5-
.project
6-
*.class
7-
# Package Files #
8-
*.jar
9-
*.war
10-
*.ear
11-
.idea
12-
*.iml
13-
*.swp
1+
target
2+
.metadata
3+
.settings
4+
.classpath
5+
.project
6+
*.class
7+
# Package Files #
8+
*.jar
9+
*.war
10+
*.ear
11+
.idea
12+
*.iml
13+
*.swp
1414
datanucleus.log
1515
/bin/
1616
/bin/
1717
/bin/
18-
19-
data-mapper/src/main/resources/log4j.xml
18+
*.log
19+
data-mapper/src/main/resources/log4j.xml

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

Lines changed: 10 additions & 7 deletions
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

Lines changed: 13 additions & 8 deletions
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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 7 additions & 2 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 9 additions & 4 deletions
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

Lines changed: 9 additions & 4 deletions
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

Lines changed: 9 additions & 4 deletions
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
}

0 commit comments

Comments
 (0)