GeezerVison is showing github.com — #502 Replaced usages of System.out with logger. · coding0011/java-design-patterns@0438811
File treeExpand file treeCollapse file tree Open diff view settings abstract-document/src/main/java/com/iluwatar/abstractdocument abstract-factory/src/main/java/com/iluwatar/abstractfactory adapter/src/main/java/com/iluwatar/adapter aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices async-method-invocation/src/main/java/com/iluwatar/async/method/invocation bridge/src/main/java/com/iluwatar/bridge builder/src/main/java/com/iluwatar/builder business-delegate/src/main/java/com/iluwatar/business/delegate caching/src/main/java/com/iluwatar/caching callback/src/main/java/com/iluwatar/callback chain/src/main/java/com/iluwatar/chain command/src/main/java/com/iluwatar/command composite/src/main/java/com/iluwatar/composite decorator/src/main/java/com/iluwatar/decorator delegation/src/main/java/com/iluwatar/delegation/simple/printers dependency-injection/src/main/java/com/iluwatar/dependency/injection double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking double-dispatch/src/main/java/com/iluwatar/doubledispatch event-aggregator/src/main/java/com/iluwatar/event/aggregator event-driven-architecture/src/main/java/com/iluwatar/eda/handler facade/src/main/java/com/iluwatar/facade factory-kit/src/main/java/com/iluwatar/factorykit factory-method/src/main/java/com/iluwatar/factory/method feature-toggle/src/main/java/com/iluwatar/featuretoggle fluentinterface/src/main/java/com/iluwatar/fluentinterface/app flux/src/main/java/com/iluwatar/flux/view flyweight/src/main/java/com/iluwatar/flyweight front-controller/src/main/java/com/iluwatar/front/controller half-sync-half-async/src/main/java/com/iluwatar/halfsynchalfasync hexagonal/src/main/java/com/iluwatar/hexagonal interpreter/src/main/java/com/iluwatar/interpreter iterator/src/main/java/com/iluwatar/iterator main/java/com/iluwatar/layers test/java/com/iluwatar/layers
lazy-loading/src/main/java/com/iluwatar/lazy/loading mediator/src/main/java/com/iluwatar/mediator memento/src/main/java/com/iluwatar/memento message-channel/src/main/java/com/iluwatar/message/channel model-view-controller/src/main/java/com/iluwatar/model/view/controller monad/src/main/java/com/iluwatar/monad monostate/src/main/java/com/iluwatar/monostate multiton/src/main/java/com/iluwatar/multiton main/java/com/iluwatar/mute test/java/com/iluwatar/mute
mutex/src/main/java/com/iluwatar/mutex webapp/src/main/webapp/WEB-INF
null-object/src/main/java/com/iluwatar/nullobject object-pool/src/main/java/com/iluwatar/object/pool observer/src/main/java/com/iluwatar/observer poison-pill/src/main/java/com/iluwatar/poison/pill private-class-data/src/main/java/com/iluwatar/privateclassdata producer-consumer/src/main/java/com/iluwatar/producer/consumer promise/src/main/java/com/iluwatar/promise property/src/main/java/com/iluwatar/property prototype/src/main/java/com/iluwatar/prototype proxy/src/main/java/com/iluwatar/proxy publish-subscribe/src/main/java/com/iluwatar/publish/subscribe reactor/src/main/java/com/iluwatar/reactor main/java/com/iluwatar/reader/writer/lock test/java/com/iluwatar/reader/writer/lock
repository/src/main/java/com/iluwatar/repository resource-acquisition-is-initialization/src/main/java/com/iluwatar/resource/acquisition/is/initialization semaphore/src/main/java/com/iluwatar/semaphore servant/src/main/java/com/iluwatar/servant service-layer/src/main/java/com/iluwatar/servicelayer service-locator/src/main/java/com/iluwatar/servicelocator singleton/src/main/java/com/iluwatar/singleton specification/src/main/java/com/iluwatar/specification/app state/src/main/java/com/iluwatar/state step-builder/src/main/java/com/iluwatar/stepbuilder strategy/src/main/java/com/iluwatar/strategy template-method/src/main/java/com/iluwatar/templatemethod thread-pool/src/main/java/com/iluwatar/threadpool tolerant-reader/src/main/java/com/iluwatar/tolerantreader twin/src/main/java/com/iluwatar/twin value-object/src/main/java/com/iluwatar/value/object visitor/src/main/java/com/iluwatar/visitor
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: abstract-document/src/main/java/com/iluwatar/abstractdocument/App.java +10-7Lines changed: 10 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | import com.iluwatar.abstractdocument.domain.HasParts; | 28 | 28 | import com.iluwatar.abstractdocument.domain.HasPrice; | 29 | 29 | import com.iluwatar.abstractdocument.domain.HasType; | | 30 | +import org.slf4j.Logger; | | 31 | +import org.slf4j.LoggerFactory; | 30 | 32 |
| 31 | 33 | import java.util.Arrays; | 32 | 34 | import java.util.HashMap; | | 44 | 46 | */ | 45 | 47 | public class App { | 46 | 48 |
| | 49 | + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); | | 50 | + | 47 | 51 | /** | 48 | 52 | * Executes the App | 49 | 53 | */ | 50 | 54 | public App() { | 51 | | - System.out.println("Constructing parts and car"); | | 55 | + LOGGER.info("Constructing parts and car"); | 52 | 56 |
| 53 | 57 | Map<String, Object> carProperties = new HashMap<>(); | 54 | 58 | carProperties.put(HasModel.PROPERTY, "300SL"); | @@ -68,12 +72,11 @@ public App() { | 68 | 72 |
| 69 | 73 | Car car = new Car(carProperties); | 70 | 74 |
| 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())); | 77 | 80 | } | 78 | 81 |
| 79 | 82 | /** | |
Collapse file Copy file name to clipboardExpand all lines: abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java +13-8Lines changed: 13 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | */ | 23 | 23 | package com.iluwatar.abstractfactory; | 24 | 24 |
| | 25 | +import org.slf4j.Logger; | | 26 | +import org.slf4j.LoggerFactory; | | 27 | + | 25 | 28 | /** | 26 | 29 | * | 27 | 30 | * The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme | | 39 | 42 | */ | 40 | 43 | public class App { | 41 | 44 |
| | 45 | + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); | | 46 | + | 42 | 47 | private King king; | 43 | 48 | private Castle castle; | 44 | 49 | private Army army; | @@ -98,17 +103,17 @@ public static void main(String[] args) { | 98 | 103 |
| 99 | 104 | App app = new App(); | 100 | 105 |
| 101 | | - System.out.println("Elf Kingdom"); | | 106 | + LOGGER.info("Elf Kingdom"); | 102 | 107 | 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()); | 106 | 111 |
| 107 | | - System.out.println("\nOrc Kingdom"); | | 112 | + LOGGER.info("Orc Kingdom"); | 108 | 113 | 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()); | 112 | 117 |
| 113 | 118 | } | 114 | 119 |
| |
Collapse file Copy file name to clipboardExpand all lines: adapter/src/main/java/com/iluwatar/adapter/BattleFishingBoat.java +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | */ | 23 | 23 | package com.iluwatar.adapter; | 24 | 24 |
| | 25 | +import org.slf4j.Logger; | | 26 | +import org.slf4j.LoggerFactory; | | 27 | + | 25 | 28 | /** | 26 | 29 | * | 27 | 30 | * Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip} | | 33 | 36 | */ | 34 | 37 | public class BattleFishingBoat implements BattleShip { | 35 | 38 |
| | 39 | + private static final Logger LOGGER = LoggerFactory.getLogger(BattleFishingBoat.class); | | 40 | + | 36 | 41 | private FishingBoat boat; | 37 | 42 |
| 38 | 43 | public BattleFishingBoat() { | @@ -41,7 +46,7 @@ public BattleFishingBoat() { | 41 | 46 |
| 42 | 47 | @Override | 43 | 48 | public void fire() { | 44 | | - System.out.println("fire!"); | | 49 | + LOGGER.info("fire!"); | 45 | 50 | } | 46 | 51 |
| 47 | 52 | @Override | |
Collapse file Copy file name to clipboardExpand all lines: adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | */ | 23 | 23 | package com.iluwatar.adapter; | 24 | 24 |
| | 25 | +import org.slf4j.Logger; | | 26 | +import org.slf4j.LoggerFactory; | | 27 | + | 25 | 28 | /** | 26 | 29 | * | 27 | 30 | * Device class (adaptee in the pattern). We want to reuse this class | 28 | 31 | * | 29 | 32 | */ | 30 | 33 | public class FishingBoat { | 31 | 34 |
| | 35 | + private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class); | | 36 | + | 32 | 37 | public void sail() { | 33 | | - System.out.println("The Boat is moving to that place"); | | 38 | + LOGGER.info("The Boat is moving to that place"); | 34 | 39 | } | 35 | 40 |
| 36 | 41 | public void fish() { | 37 | | - System.out.println("fishing ..."); | | 42 | + LOGGER.info("fishing ..."); | 38 | 43 | } | 39 | 44 |
| 40 | 45 | } |
Collapse file Copy file name to clipboardExpand all lines: aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInformationClientImpl.java +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | import org.apache.http.impl.client.CloseableHttpClient; | 28 | 28 | import org.apache.http.impl.client.HttpClients; | 29 | 29 | import org.apache.http.util.EntityUtils; | | 30 | +import org.slf4j.Logger; | | 31 | +import org.slf4j.LoggerFactory; | 30 | 32 | import org.springframework.stereotype.Component; | 31 | 33 |
| 32 | 34 | import java.io.IOException; | | 37 | 39 | @Component | 38 | 40 | public class ProductInformationClientImpl implements ProductInformationClient { | 39 | 41 |
| | 42 | + private static final Logger LOGGER = LoggerFactory.getLogger(ProductInformationClientImpl.class); | | 43 | + | 40 | 44 | @Override | 41 | 45 | public String getProductTitle() { | 42 | 46 | String response = null; | @@ -46,7 +50,7 @@ public String getProductTitle() { | 46 | 50 | response = EntityUtils.toString(httpResponse.getEntity()); | 47 | 51 | } | 48 | 52 | } catch (IOException e) { | 49 | | - e.printStackTrace(); | | 53 | + LOGGER.error("Exception caught.", e); | 50 | 54 | } | 51 | 55 | return response; | 52 | 56 | } | |
Collapse file Copy file name to clipboardExpand all lines: aggregator-microservices/aggregator-service/src/main/java/com/iluwatar/aggregator/microservices/ProductInventoryClientImpl.java +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | import org.apache.http.impl.client.CloseableHttpClient; | 28 | 28 | import org.apache.http.impl.client.HttpClients; | 29 | 29 | import org.apache.http.util.EntityUtils; | | 30 | +import org.slf4j.Logger; | | 31 | +import org.slf4j.LoggerFactory; | 30 | 32 | import org.springframework.stereotype.Component; | 31 | 33 |
| 32 | 34 | import java.io.IOException; | | 37 | 39 | @Component | 38 | 40 | public class ProductInventoryClientImpl implements ProductInventoryClient { | 39 | 41 |
| | 42 | + private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class); | | 43 | + | 40 | 44 | @Override | 41 | 45 | public int getProductInventories() { | 42 | 46 | String response = "0"; | @@ -46,7 +50,7 @@ public int getProductInventories() { | 46 | 50 | response = EntityUtils.toString(httpResponse.getEntity()); | 47 | 51 | } | 48 | 52 | } catch (IOException e) { | 49 | | - e.printStackTrace(); | | 53 | + LOGGER.error("Exception caught.", e); | 50 | 54 | } | 51 | 55 | return Integer.parseInt(response); | 52 | 56 | } | |
Collapse file Copy file name to clipboardExpand all lines: async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | */ | 23 | 23 | package com.iluwatar.async.method.invocation; | 24 | 24 |
| | 25 | +import org.slf4j.Logger; | | 26 | +import org.slf4j.LoggerFactory; | | 27 | + | 25 | 28 | import java.util.concurrent.Callable; | 26 | 29 |
| 27 | 30 | /** | | 54 | 57 | */ | 55 | 58 | public class App { | 56 | 59 |
| | 60 | + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); | | 61 | + | 57 | 62 | /** | 58 | 63 | * Program entry point | 59 | 64 | */ | @@ -120,6 +125,6 @@ private static <T> AsyncCallback<T> callback(String name) { | 120 | 125 | } | 121 | 126 |
| 122 | 127 | private static void log(String msg) { | 123 | | - System.out.println(String.format("[%1$-10s] - %2$s", Thread.currentThread().getName(), msg)); | | 128 | + LOGGER.info(msg); | 124 | 129 | } | 125 | 130 | } |
Collapse file Copy file name to clipboardExpand all lines: bridge/src/main/java/com/iluwatar/bridge/Excalibur.java +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | */ | 23 | 23 | package com.iluwatar.bridge; | 24 | 24 |
| | 25 | +import org.slf4j.Logger; | | 26 | +import org.slf4j.LoggerFactory; | | 27 | + | 25 | 28 | /** | 26 | 29 | * | 27 | 30 | * Excalibur | 28 | 31 | * | 29 | 32 | */ | 30 | 33 | public class Excalibur extends BlindingMagicWeaponImpl { | 31 | 34 |
| | 35 | + private static final Logger LOGGER = LoggerFactory.getLogger(Excalibur.class); | | 36 | + | 32 | 37 | @Override | 33 | 38 | public void wieldImp() { | 34 | | - System.out.println("wielding Excalibur"); | | 39 | + LOGGER.info("wielding Excalibur"); | 35 | 40 | } | 36 | 41 |
| 37 | 42 | @Override | 38 | 43 | public void swingImp() { | 39 | | - System.out.println("swinging Excalibur"); | | 44 | + LOGGER.info("swinging Excalibur"); | 40 | 45 | } | 41 | 46 |
| 42 | 47 | @Override | 43 | 48 | public void unwieldImp() { | 44 | | - System.out.println("unwielding Excalibur"); | | 49 | + LOGGER.info("unwielding Excalibur"); | 45 | 50 | } | 46 | 51 |
| 47 | 52 | @Override | 48 | 53 | 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"); | 50 | 55 | } | 51 | 56 | } |
Collapse file Copy file name to clipboardExpand all lines: bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | */ | 23 | 23 | package com.iluwatar.bridge; | 24 | 24 |
| | 25 | +import org.slf4j.Logger; | | 26 | +import org.slf4j.LoggerFactory; | | 27 | + | 25 | 28 | /** | 26 | 29 | * | 27 | 30 | * Mjollnir | 28 | 31 | * | 29 | 32 | */ | 30 | 33 | public class Mjollnir extends FlyingMagicWeaponImpl { | 31 | 34 |
| | 35 | + private static final Logger LOGGER = LoggerFactory.getLogger(Mjollnir.class); | | 36 | + | 32 | 37 | @Override | 33 | 38 | public void wieldImp() { | 34 | | - System.out.println("wielding Mjollnir"); | | 39 | + LOGGER.info("wielding Mjollnir"); | 35 | 40 | } | 36 | 41 |
| 37 | 42 | @Override | 38 | 43 | public void swingImp() { | 39 | | - System.out.println("swinging Mjollnir"); | | 44 | + LOGGER.info("swinging Mjollnir"); | 40 | 45 | } | 41 | 46 |
| 42 | 47 | @Override | 43 | 48 | public void unwieldImp() { | 44 | | - System.out.println("unwielding Mjollnir"); | | 49 | + LOGGER.info("unwielding Mjollnir"); | 45 | 50 | } | 46 | 51 |
| 47 | 52 | @Override | 48 | 53 | 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"); | 50 | 55 | } | 51 | 56 | } |
Collapse file Copy file name to clipboardExpand all lines: bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | */ | 23 | 23 | package com.iluwatar.bridge; | 24 | 24 |
| | 25 | +import org.slf4j.Logger; | | 26 | +import org.slf4j.LoggerFactory; | | 27 | + | 25 | 28 | /** | 26 | 29 | * | 27 | 30 | * Stormbringer | 28 | 31 | * | 29 | 32 | */ | 30 | 33 | public class Stormbringer extends SoulEatingMagicWeaponImpl { | 31 | 34 |
| | 35 | + private static final Logger LOGGER = LoggerFactory.getLogger(Stormbringer.class); | | 36 | + | 32 | 37 | @Override | 33 | 38 | public void wieldImp() { | 34 | | - System.out.println("wielding Stormbringer"); | | 39 | + LOGGER.info("wielding Stormbringer"); | 35 | 40 | } | 36 | 41 |
| 37 | 42 | @Override | 38 | 43 | public void swingImp() { | 39 | | - System.out.println("swinging Stormbringer"); | | 44 | + LOGGER.info("swinging Stormbringer"); | 40 | 45 | } | 41 | 46 |
| 42 | 47 | @Override | 43 | 48 | public void unwieldImp() { | 44 | | - System.out.println("unwielding Stormbringer"); | | 49 | + LOGGER.info("unwielding Stormbringer"); | 45 | 50 | } | 46 | 51 |
| 47 | 52 | @Override | 48 | 53 | public void eatSoulImp() { | 49 | | - System.out.println("Stormbringer devours the enemy's soul"); | | 54 | + LOGGER.info("Stormbringer devours the enemy's soul"); | 50 | 55 | } | 51 | 56 | } |
|