#970 single logging framework should be enforced (#982)

* #496 Add pipeline module to parent pom 

* #496: Add main application class and test for pipeline

* #496: Checkstyle format and add log messages on pipeline stages 🎨

* #496: Fill readme sections of pipeline 

* #496: Javadocs and checkstyle formatting 🎨

* #496: Follow PMD checks and add more explanation as block comment on App.java

* #496: Apply requested PR changes by iluwatar 🎨

* #970: Replace log4j usage on commander pattern to Slf4j API 🎨

* #970: Replace log4j usage on dao pattern to Slf4j API 🎨

* #970: Replace log4j usage on data mapper pattern to Slf4j API 🎨

* #970: Remove log4j dependency on data transfer object pom 🔥

* #970: Replace log4j usage on module pattern to Slf4j API 🎨

* #970: Replace log4j usage on serverless pattern to Slf4j API 🎨

This also removes the aws log4j dependency

* #970: Remove unnecessary gitignore line for log4j.xml 🔥

* #970: Remove remaining remnants of log4j 🔥

* #970: Replace System.out logging with appropriate logging methods 🎨

* #970: Replace System.out method references to Logger::info 🎨
This commit is contained in:
Joshua Jimenez
2019-10-14 04:41:11 +08:00
committed by Ilkka Seppälä
parent 72b174619f
commit cfdfedbd2e
50 changed files with 163 additions and 410 deletions

View File

@@ -36,10 +36,5 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</project>

View File

@@ -1,41 +0,0 @@
#
# The MIT License
# Copyright © 2014-2019 Ilkka Seppälä
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#Define root logger options
log4j.rootLogger=TRACE, file, console
#Define console appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
logrj.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd} %d{HH:mm:ss} %5p[%t] %m%n
#Define rolling file appender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/log/logFile.log
log4j.appender.file.Append=true
log4j.appender.file.ImmediateFlush=true
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=5
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d %d{HH:mm:ss} %5p[%t] %m%n

View File

@@ -23,7 +23,6 @@
package com.iluwatar.commander;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import com.iluwatar.commander.employeehandle.EmployeeHandle;
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
import com.iluwatar.commander.exceptions.ItemUnavailableException;
@@ -37,6 +36,8 @@ import com.iluwatar.commander.queue.QueueDatabase;
import com.iluwatar.commander.queue.QueueTask;
import com.iluwatar.commander.queue.QueueTask.TaskType;
import com.iluwatar.commander.shippingservice.ShippingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*<p>Commander pattern is used to handle all issues that can come up while making a
@@ -86,7 +87,7 @@ public class Commander {
private final long messageTime;
private final long employeeTime;
private boolean finalSiteMsgShown;
static final Logger LOG = Logger.getLogger(Commander.class);
static final Logger LOG = LoggerFactory.getLogger(Commander.class);
//we could also have another db where it stores all orders
Commander(EmployeeHandle empDb, PaymentService pService, ShippingService sService,
@@ -125,27 +126,27 @@ public class Commander {
String transactionId = shippingService.receiveRequest(order.item, order.user.address);
//could save this transaction id in a db too
LOG.info("Order " + order.id + ": Shipping placed successfully, transaction id: " + transactionId);
System.out.println("Order has been placed and will be shipped to you. Please wait while we make your"
LOG.info("Order has been placed and will be shipped to you. Please wait while we make your"
+ " payment... ");
sendPaymentRequest(order);
return;
};
Retry.HandleErrorIssue<Order> handleError = (o,err) -> {
if (ShippingNotPossibleException.class.isAssignableFrom(err.getClass())) {
System.out.println("Shipping is currently not possible to your address. We are working on the problem "
LOG.info("Shipping is currently not possible to your address. We are working on the problem "
+ "and will get back to you asap.");
finalSiteMsgShown = true;
LOG.info("Order " + order.id + ": Shipping not possible to address, trying to add problem to employee db..");
employeeHandleIssue(o);
} else if (ItemUnavailableException.class.isAssignableFrom(err.getClass())) {
System.out.println("This item is currently unavailable. We will inform you as soon as the item becomes "
LOG.info("This item is currently unavailable. We will inform you as soon as the item becomes "
+ "available again.");
finalSiteMsgShown = true;
LOG.info("Order " + order.id + ": Item " + order.item + " unavailable, trying to add problem to employee "
+ "handle..");
employeeHandleIssue(o);
} else {
System.out.println("Sorry, there was a problem in creating your order. Please try later.");
LOG.info("Sorry, there was a problem in creating your order. Please try later.");
LOG.error("Order " + order.id + ": Shipping service unavailable, order not placed..");
finalSiteMsgShown = true;
}
@@ -183,7 +184,7 @@ public class Commander {
order.paid = PaymentStatus.Done;
LOG.info("Order " + order.id + ": Payment successful, transaction Id: " + transactionId);
if (!finalSiteMsgShown) {
System.out.println("Payment made successfully, thank you for shopping with us!!");
LOG.info("Payment made successfully, thank you for shopping with us!!");
finalSiteMsgShown = true;
}
sendSuccessMessage(order);
@@ -193,7 +194,7 @@ public class Commander {
Retry.HandleErrorIssue<Order> handleError = (o,err) -> {
if (PaymentDetailsErrorException.class.isAssignableFrom(err.getClass())) {
if (!finalSiteMsgShown) {
System.out.println("There was an error in payment. Your account/card details may have been incorrect. "
LOG.info("There was an error in payment. Your account/card details may have been incorrect. "
+ "Meanwhile, your order has been converted to COD and will be shipped.");
finalSiteMsgShown = true;
}
@@ -204,7 +205,7 @@ public class Commander {
try {
if (o.messageSent.equals(MessageSent.NoneSent)) {
if (!finalSiteMsgShown) {
System.out.println("There was an error in payment. We are on it, and will get back to you "
LOG.info("There was an error in payment. We are on it, and will get back to you "
+ "asap. Don't worry, your order has been placed and will be shipped.");
finalSiteMsgShown = true;
}

View File

@@ -24,6 +24,8 @@ package com.iluwatar.commander.messagingservice;
import com.iluwatar.commander.Service;
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The MessagingService is used to send messages to user regarding their order and
@@ -32,6 +34,7 @@ import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
*/
public class MessagingService extends Service {
private static final Logger LOGGER = LoggerFactory.getLogger(MessagingService.class);
enum MessageToSend {
PaymentFail, PaymentTrying, PaymentSuccessful
@@ -74,7 +77,7 @@ public class MessagingService extends Service {
MessageRequest req = (MessageRequest) parameters[0];
if (this.database.get(req.reqId) == null) { //idempotence, in case db fails here
database.add(req); //if successful:
System.out.println(sendMessage(req.msg));
LOGGER.info(sendMessage(req.msg));
return req.reqId;
}
return null;