GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — #970 single logging framework should be enforced (#982) · coding0011/java-design-patterns@cfdfedb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .gitignore
  • collection-pipeline/src/test/java/com/iluwatar/collectionpipeline
    • AppTest.java
  • commander
    • pom.xml
    • properties
      • log4j.properties
    • src/main/java/com/iluwatar/commander
      • Commander.java
      • messagingservice
        • MessagingService.java
  • converter/src/main/java/com/iluwatar/converter
    • App.java
  • dao
    • pom.xml
    • src/main
      • java/com/iluwatar/dao
        • App.java
        • DbCustomerDao.java
      • resources
        • log4j.xml
  • data-mapper
    • pom.xml
    • src/main
      • java/com/iluwatar/datamapper
        • App.java
      • resources
        • log4j.xml
  • data-transfer-object
    • pom.xml
  • dirty-flag/src/main/java/com/iluwatar/dirtyflag
    • App.java
    • DataFetcher.java
  • event-queue/src/main/java/com/iluwatar/event/queue
    • App.java
  • hexagonal/src/main/java/com/iluwatar/hexagonal
    • administration
      • ConsoleAdministration.java
    • service
      • ConsoleLottery.java
      • LotteryConsoleServiceImpl.java
  • master-worker-pattern/src/main/java/com/iluwatar/masterworker
    • App.java
    • ArrayUtilityMethods.java
  • module
    • pom.xml
    • src
      • main
        • java/com/iluwatar/module
          • ConsoleLoggerModule.java
          • FileLoggerModule.java
        • resources
          • log4j.xml
      • test/java/com/iluwatar/module
        • FileLoggerModuleTest.java
  • naked-objects
    • dom
      • exclude-pmd.properties
      • pom.xml
    • integtests/src/test/java/domainapp/integtests
      • bootstrap
        • SimpleAppSystemInitializer.java
      • specglue
        • BootstrappingGlue.java
      • tests
        • SimpleAppIntegTest.java
    • webapp
      • pom.xml
      • src/main/java/domainapp/webapp
        • SimpleApplication.java
  • pipeline/src/main/java/com.iluwatar.pipeline
    • ConvertToCharArrayHandler.java
    • RemoveAlphabetsHandler.java
    • RemoveDigitsHandler.java
  • pom.xml
  • serverless
    • pom.xml
    • src/main
      • java/com/iluwatar/serverless
        • baas/api
          • FindPersonApiHandler.java
          • SavePersonApiHandler.java
        • faas/api
          • LambdaInfoApiHandler.java
      • resources
        • log4j.properties
  • spatial-partition/src/main/java/com/iluwatar/spatialpartition
    • App.java
    • Bubble.java
  • tls/src/main/java/com/iluwatar/tls
    • App.java
    • DateFormatCallable.java
  • typeobjectpattern/src/main/java/com/iluwatar/typeobject
    • App.java
    • CandyGame.java

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboardExpand all lines: .gitignore
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ datanucleus.log
1616
/bin/
1717
/bin/
1818
*.log
19-
data-mapper/src/main/resources/log4j.xml
2019
event-sourcing/Journal.json
Collapse file

‎collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java‎

Copy file name to clipboardExpand all lines: collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@
3030
import java.util.Map;
3131

3232
import org.junit.jupiter.api.Test;
33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
3335

3436
/**
3537
* Tests that Collection Pipeline methods work as expected.
3638
*/
3739
public class AppTest {
38-
40+
private static final Logger LOGGER = LoggerFactory.getLogger(AppTest.class);
41+
3942
private List<Car> cars = CarFactory.createCars();
4043

4144
@Test
@@ -61,7 +64,7 @@ public void testGetGroupingOfCarsByCategory() {
6164
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
6265
Map<Category, List<Car>> modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
6366
Map<Category, List<Car>> modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
64-
System.out.println("Category " + modelsFunctional);
67+
LOGGER.info("Category " + modelsFunctional);
6568
assertEquals(modelsExpected, modelsFunctional);
6669
assertEquals(modelsExpected, modelsImperative);
6770
}
Collapse file

‎commander/pom.xml‎

Copy file name to clipboardExpand all lines: commander/pom.xml
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,5 @@
3636
<artifactId>junit-jupiter-engine</artifactId>
3737
<scope>test</scope>
3838
</dependency>
39-
<dependency>
40-
<groupId>log4j</groupId>
41-
<artifactId>log4j</artifactId>
42-
<version>1.2.17</version>
43-
</dependency>
4439
</dependencies>
4540
</project>
Collapse file

‎commander/properties/log4j.properties‎

Copy file name to clipboardExpand all lines: commander/properties/log4j.properties
-41Lines changed: 0 additions & 41 deletions
This file was deleted.
Collapse file

‎commander/src/main/java/com/iluwatar/commander/Commander.java‎

Copy file name to clipboardExpand all lines: commander/src/main/java/com/iluwatar/commander/Commander.java
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package com.iluwatar.commander;
2424

2525
import java.util.ArrayList;
26-
import org.apache.log4j.Logger;
2726
import com.iluwatar.commander.employeehandle.EmployeeHandle;
2827
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
2928
import com.iluwatar.commander.exceptions.ItemUnavailableException;
@@ -37,6 +36,8 @@
3736
import com.iluwatar.commander.queue.QueueTask;
3837
import com.iluwatar.commander.queue.QueueTask.TaskType;
3938
import com.iluwatar.commander.shippingservice.ShippingService;
39+
import org.slf4j.Logger;
40+
import org.slf4j.LoggerFactory;
4041

4142
/**
4243
*<p>Commander pattern is used to handle all issues that can come up while making a
@@ -86,7 +87,7 @@ public class Commander {
8687
private final long messageTime;
8788
private final long employeeTime;
8889
private boolean finalSiteMsgShown;
89-
static final Logger LOG = Logger.getLogger(Commander.class);
90+
static final Logger LOG = LoggerFactory.getLogger(Commander.class);
9091
//we could also have another db where it stores all orders
9192

9293
Commander(EmployeeHandle empDb, PaymentService pService, ShippingService sService,
@@ -125,27 +126,27 @@ private void sendShippingRequest(Order order) throws Exception {
125126
String transactionId = shippingService.receiveRequest(order.item, order.user.address);
126127
//could save this transaction id in a db too
127128
LOG.info("Order " + order.id + ": Shipping placed successfully, transaction id: " + transactionId);
128-
System.out.println("Order has been placed and will be shipped to you. Please wait while we make your"
129+
LOG.info("Order has been placed and will be shipped to you. Please wait while we make your"
129130
+ " payment... ");
130131
sendPaymentRequest(order);
131132
return;
132133
};
133134
Retry.HandleErrorIssue<Order> handleError = (o,err) -> {
134135
if (ShippingNotPossibleException.class.isAssignableFrom(err.getClass())) {
135-
System.out.println("Shipping is currently not possible to your address. We are working on the problem "
136+
LOG.info("Shipping is currently not possible to your address. We are working on the problem "
136137
+ "and will get back to you asap.");
137138
finalSiteMsgShown = true;
138139
LOG.info("Order " + order.id + ": Shipping not possible to address, trying to add problem to employee db..");
139140
employeeHandleIssue(o);
140141
} else if (ItemUnavailableException.class.isAssignableFrom(err.getClass())) {
141-
System.out.println("This item is currently unavailable. We will inform you as soon as the item becomes "
142+
LOG.info("This item is currently unavailable. We will inform you as soon as the item becomes "
142143
+ "available again.");
143144
finalSiteMsgShown = true;
144145
LOG.info("Order " + order.id + ": Item " + order.item + " unavailable, trying to add problem to employee "
145146
+ "handle..");
146147
employeeHandleIssue(o);
147148
} else {
148-
System.out.println("Sorry, there was a problem in creating your order. Please try later.");
149+
LOG.info("Sorry, there was a problem in creating your order. Please try later.");
149150
LOG.error("Order " + order.id + ": Shipping service unavailable, order not placed..");
150151
finalSiteMsgShown = true;
151152
}
@@ -183,7 +184,7 @@ public void run() {
183184
order.paid = PaymentStatus.Done;
184185
LOG.info("Order " + order.id + ": Payment successful, transaction Id: " + transactionId);
185186
if (!finalSiteMsgShown) {
186-
System.out.println("Payment made successfully, thank you for shopping with us!!");
187+
LOG.info("Payment made successfully, thank you for shopping with us!!");
187188
finalSiteMsgShown = true;
188189
}
189190
sendSuccessMessage(order);
@@ -193,7 +194,7 @@ public void run() {
193194
Retry.HandleErrorIssue<Order> handleError = (o,err) -> {
194195
if (PaymentDetailsErrorException.class.isAssignableFrom(err.getClass())) {
195196
if (!finalSiteMsgShown) {
196-
System.out.println("There was an error in payment. Your account/card details may have been incorrect. "
197+
LOG.info("There was an error in payment. Your account/card details may have been incorrect. "
197198
+ "Meanwhile, your order has been converted to COD and will be shipped.");
198199
finalSiteMsgShown = true;
199200
}
@@ -204,7 +205,7 @@ public void run() {
204205
try {
205206
if (o.messageSent.equals(MessageSent.NoneSent)) {
206207
if (!finalSiteMsgShown) {
207-
System.out.println("There was an error in payment. We are on it, and will get back to you "
208+
LOG.info("There was an error in payment. We are on it, and will get back to you "
208209
+ "asap. Don't worry, your order has been placed and will be shipped.");
209210
finalSiteMsgShown = true;
210211
}
Collapse file

‎commander/src/main/java/com/iluwatar/commander/messagingservice/MessagingService.java‎

Copy file name to clipboardExpand all lines: commander/src/main/java/com/iluwatar/commander/messagingservice/MessagingService.java
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import com.iluwatar.commander.Service;
2626
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2729

2830
/**
2931
* The MessagingService is used to send messages to user regarding their order and
@@ -32,6 +34,7 @@
3234
*/
3335

3436
public class MessagingService extends Service {
37+
private static final Logger LOGGER = LoggerFactory.getLogger(MessagingService.class);
3538

3639
enum MessageToSend {
3740
PaymentFail, PaymentTrying, PaymentSuccessful
@@ -74,7 +77,7 @@ protected String updateDb(Object...parameters) throws DatabaseUnavailableExcepti
7477
MessageRequest req = (MessageRequest) parameters[0];
7578
if (this.database.get(req.reqId) == null) { //idempotence, in case db fails here
7679
database.add(req); //if successful:
77-
System.out.println(sendMessage(req.msg));
80+
LOGGER.info(sendMessage(req.msg));
7881
return req.reqId;
7982
}
8083
return null;
Collapse file

‎converter/src/main/java/com/iluwatar/converter/App.java‎

Copy file name to clipboardExpand all lines: converter/src/main/java/com/iluwatar/converter/App.java
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525

2626
import com.google.common.collect.Lists;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2729

2830
import java.util.ArrayList;
2931
import java.util.List;
@@ -35,6 +37,8 @@
3537
* objects between types.
3638
*/
3739
public class App {
40+
41+
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
3842
/**
3943
* Program entry point
4044
*
@@ -45,16 +49,16 @@ public static void main(String[] args) {
4549

4650
UserDto dtoUser = new UserDto("John", "Doe", true, "whatever[at]wherever.com");
4751
User user = userConverter.convertFromDto(dtoUser);
48-
System.out.println("Entity converted from DTO:" + user);
52+
LOGGER.info("Entity converted from DTO:" + user);
4953

5054
ArrayList<User> users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"),
5155
new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243"));
52-
System.out.println("Domain entities:");
53-
users.forEach(System.out::println);
56+
LOGGER.info("Domain entities:");
57+
users.stream().map(User::toString).forEach(LOGGER::info);
5458

55-
System.out.println("DTO entities converted from domain:");
59+
LOGGER.info("DTO entities converted from domain:");
5660
List<UserDto> dtoEntities = userConverter.createFromEntities(users);
57-
dtoEntities.forEach(System.out::println);
61+
dtoEntities.stream().map(UserDto::toString).forEach(LOGGER::info);
5862

5963
}
6064
}
Collapse file

‎dao/pom.xml‎

Copy file name to clipboardExpand all lines: dao/pom.xml
-49Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
<artifactId>junit-jupiter-engine</artifactId>
4141
<scope>test</scope>
4242
</dependency>
43-
<dependency>
44-
<groupId>log4j</groupId>
45-
<artifactId>log4j</artifactId>
46-
</dependency>
4743
<dependency>
4844
<groupId>com.h2database</groupId>
4945
<artifactId>h2</artifactId>
@@ -53,49 +49,4 @@
5349
<artifactId>mockito-core</artifactId>
5450
</dependency>
5551
</dependencies>
56-
57-
<build>
58-
59-
<!--
60-
log4j.xml file will be copied both in ${project.build.outputDirectory}
61-
and ${project.build.directory}. Thanks to Sean Patrick Floyd
62-
(http://stackoverflow.com/questions/5637532/maven-how-to-place-resource-file-together-with-jar)
63-
-->
64-
65-
<resources>
66-
<resource> <!-- regular processing for every resource file -->
67-
<directory>src/main/resources</directory>
68-
</resource>
69-
<resource> <!-- processing with a different output directory for log4j.xml -->
70-
<directory>src/main/resources</directory>
71-
<includes>
72-
<include>log4j.xml</include>
73-
</includes>
74-
<targetPath>..</targetPath> <!-- relative to target/classes i.e. ${project.build.directory} -->
75-
</resource>
76-
</resources>
77-
78-
<plugins>
79-
80-
<!--
81-
This will exclude log4j.xml file from generated JAR
82-
-->
83-
<plugin>
84-
<groupId>org.apache.maven.plugins</groupId>
85-
<artifactId>maven-jar-plugin</artifactId>
86-
<version>2.6</version>
87-
<configuration>
88-
<excludes>
89-
<exclude>log4j.xml</exclude>
90-
</excludes>
91-
<archive>
92-
<manifest>
93-
<addClasspath>true</addClasspath>
94-
</manifest>
95-
</archive>
96-
</configuration>
97-
</plugin>
98-
99-
</plugins>
100-
</build>
10152
</project>
Collapse file

‎dao/src/main/java/com/iluwatar/dao/App.java‎

Copy file name to clipboardExpand all lines: dao/src/main/java/com/iluwatar/dao/App.java
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131

3232
import javax.sql.DataSource;
3333

34-
import org.apache.log4j.Logger;
3534
import org.h2.jdbcx.JdbcDataSource;
35+
import org.slf4j.Logger;
36+
import org.slf4j.LoggerFactory;
3637

3738
/**
3839
* Data Access Object (DAO) is an object that provides an abstract interface to some type of
@@ -50,7 +51,7 @@
5051
*/
5152
public class App {
5253
private static final String DB_URL = "jdbc:h2:~/dao";
53-
private static Logger log = Logger.getLogger(App.class);
54+
private static Logger log = LoggerFactory.getLogger(App.class);
5455
private static final String ALL_CUSTOMERS = "customerDao.getAllCustomers(): ";
5556

5657
/**
@@ -94,7 +95,7 @@ private static void performOperationsUsing(final CustomerDao customerDao) throws
9495
addCustomers(customerDao);
9596
log.info(ALL_CUSTOMERS);
9697
try (Stream<Customer> customerStream = customerDao.getAll()) {
97-
customerStream.forEach((customer) -> log.info(customer));
98+
customerStream.forEach((customer) -> log.info(customer.toString()));
9899
}
99100
log.info("customerDao.getCustomerById(2): " + customerDao.getById(2));
100101
final Customer customer = new Customer(4, "Dan", "Danson");
@@ -105,7 +106,7 @@ private static void performOperationsUsing(final CustomerDao customerDao) throws
105106
customerDao.update(customer);
106107
log.info(ALL_CUSTOMERS);
107108
try (Stream<Customer> customerStream = customerDao.getAll()) {
108-
customerStream.forEach((cust) -> log.info(cust));
109+
customerStream.forEach((cust) -> log.info(cust.toString()));
109110
}
110111
customerDao.delete(customer);
111112
log.info(ALL_CUSTOMERS + customerDao.getAll());
Collapse file

‎dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java‎

Copy file name to clipboardExpand all lines: dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
package com.iluwatar.dao;
2424

25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2528
import java.sql.Connection;
2629
import java.sql.PreparedStatement;
2730
import java.sql.ResultSet;
@@ -35,15 +38,13 @@
3538

3639
import javax.sql.DataSource;
3740

38-
import org.apache.log4j.Logger;
39-
4041
/**
4142
* An implementation of {@link CustomerDao} that persists customers in RDBMS.
4243
*
4344
*/
4445
public class DbCustomerDao implements CustomerDao {
4546

46-
private static final Logger LOGGER = Logger.getLogger(DbCustomerDao.class);
47+
private static final Logger LOGGER = LoggerFactory.getLogger(DbCustomerDao.class);
4748

4849
private final DataSource dataSource;
4950

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.